带有sudo的Ansible“期望”模块?

Mik*_*kel 2 expect ansible

我想用 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/" 
Run Code Online (Sandbox Code Playgroud)

我原以为这会奏效,但我收到错误

fatal: [127.0.0.1]: FAILED! => {"changed": false, "failed": true, "msg": "unsupported parameter for module: become_method"}
Run Code Online (Sandbox Code Playgroud)

如果我省略“become_method”,则会出现此错误:

fatal: [127.0.0.1]: FAILED! => {"changed": false, "failed": true, "msg": "unsupported parameter for module: become"}
Run Code Online (Sandbox Code Playgroud)

我的 Ansible 是 2.1.1.0 版

Mir*_*ici 5

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

- 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/" 
Run Code Online (Sandbox Code Playgroud)

你可以省略become_method.