Ansible“expect”模块带有sudo吗?

Ansible“expect”模块带有sudo吗?

我想使用 Ansible 运行安装程序脚本。安装程序脚本会提示输入一些响应,并且需要以 root 权限运行。

以下是我的 Ansible 任务的本质:

- expect:
  become: yes
  become_method: sudo
  command: "installer.bin"
  echo: yes
  responses:
    "Choose the appropriate installation or upgrade option.": "2"
    "Where should the software be installed?": "/opt/newsoftware/" 

我原本以为这会起作用,但我收到了错误

fatal: [127.0.0.1]: FAILED! => {"changed": false, "failed": true, "msg": "unsupported parameter for module: become_method"}

如果我省略“become_method”,我会收到此错误:

fatal: [127.0.0.1]: FAILED! => {"changed": false, "failed": true, "msg": "unsupported parameter for module: become"}

我的 Ansible 是 2.1.1.0 版本

答案1

我认为你需要像这样写任务:

- expect:
  become: yes
  become_method: sudo
  args:
    command: "installer.bin"
    echo: yes
    responses:
      "Choose the appropriate installation or upgrade option.": "2"
      "Where should the software be installed?": "/opt/newsoftware/" 

您可以省略become_method

相关内容