使用Ansible运行包含引号的命令
我希望使用Ansible(3.6.5版)在远程主机上运行: 我尝试将此任务包括在我的剧本中:使用Ansible运行包含引号的命令,ansible,Ansible,我希望使用Ansible(3.6.5版)在远程主机上运行: 我尝试将此任务包括在我的剧本中: - name: dpkg-reconfigure exim4-config command: DEBCONF_DB_OVERRIDE='File /tmp/config.dat' dpkg-reconfigure -fnoninteractive exim4-config 这将导致以下错误消息: 失败!=>{“已更改”:false,“cmd”:“'DEBCONF\u DB\u OVERRIDE=F
- name: dpkg-reconfigure exim4-config
command: DEBCONF_DB_OVERRIDE='File /tmp/config.dat' dpkg-reconfigure -fnoninteractive exim4-config
这将导致以下错误消息:
失败!=>{“已更改”:false,“cmd”:“'DEBCONF\u DB\u OVERRIDE=File
/tmp/config.dat“dpkg重新配置-fNoInteractive exim4配置”,
“msg”:“[Errno 2]没有这样的文件或目录”,“rc”:2}
在我看来,Ansible的命令
模块添加了额外的引号,这似乎干扰了我的工作
那么,如何使用Ansible运行此命令呢?我已经尝试了单引号和双引号以及转义字符(使用
\'
、\“
或\
),但到目前为止都没有用。对于自定义命令,应该使用shell
而不是命令
:
- name: dpkg-reconfigure exim4-config
shell: DEBCONF_DB_OVERRIDE='File /tmp/config.dat' dpkg-reconfigure -fnoninteractive exim4-config
DEBCONF\u DB\u OVERRIDE='File/tmp/config.dat'
是DEBCONF\u DB\u OVERRIDE变量的设置值,然后运行命令dpkg reconfigure-fnoninteractive exim4 config
- name: dpkg-reconfigure exim4-config
shell: DEBCONF_DB_OVERRIDE='File /tmp/config.dat' dpkg-reconfigure -fnoninteractive exim4-config