Ansible

帶有 sudo 的 Ansible“期望”模組?

  • September 26, 2016

我想用 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 版

我認為您需要編寫如下任務:

- 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.

引用自:https://serverfault.com/questions/805391