首页 文章

运行命令,包括带有Ansible [duplicate]的引号

提问于
浏览
0

这个问题在这里已有答案:

我想在Ansible(版本(3.6.5)的远程主机上运行this command

DEBCONF_DB_OVERRIDE='File /tmp/config.dat' dpkg-reconfigure -fnoninteractive exim4-config

我尝试将此任务包含在我的剧本中:

- name: dpkg-reconfigure exim4-config
  command: DEBCONF_DB_OVERRIDE='File /tmp/config.dat' dpkg-reconfigure -fnoninteractive exim4-config

这会导致以下错误消息:

失败了! => {“已更改”:false,“cmd”:“'DEBCONF_DB_OVERRIDE =文件/tmp/config.dat'dpkg-configure-fnoninteractive exim4-config”,“msg”:“[Errno 2]没有这样的文件或目录” ,“rc”:2}

它看起来好像Ansible的 command 模块放置了额外的周围报价,这似乎打扰了我的 .

那么如何用Ansible运行这个命令呢?我已尝试过单引号和双引号以及转义字符(使用 \'\"\ ),但到目前为止无济于事 .

1 回答

  • 1

    对于自定义命令,您应该使用 shell 而不是 command

    - name: dpkg-reconfigure exim4-config
        shell: DEBCONF_DB_OVERRIDE='File /tmp/config.dat' dpkg-reconfigure -fnoninteractive exim4-config
    

相关问题