我正在编写一个用于自动安装 anaconda 的剧本。我正在使用 Ansible expect 模块来回答安装提示。这是我的代码。
---
- hosts: all
become: yes
become_method: sudo
gather_facts: true
tasks:
- name: Run the installer Anaconda
expect:
command: bash ~/Downloads/Anaconda3-2019.03-Linux-x86_64.sh
responses:
"Please, press ENTER to continue" : "\n"
"More" : " "
" Do you accept the license terms" : "yes"
"Press ENTER to confirm the location" : "\n"
"Do you wish the installer to initialize Anaconda3 by running conda init": "yes"
这是我得到的错误。任务 [运行安装程序 Anaconda] ***************************************************
致命:[192.168.6.230]:失败! => {“changed”:false,“msg”:“(expect)模块不支持的参数:您是否接受许可条款,您是否希望安装程序通过运行 conda init 来初始化 Anaconda3,更多,请按 ENTER 继续,按 ENTER 确认位置支持的参数包括:chdir、command、creates、echo、removes、response、timeout”}
答案1
您需要缩进您的回复:
responses:
- "Please, press ENTER to continue" : "\n"
- "More" : " "
- " Do you accept the license terms" : "yes"
- "Press ENTER to confirm the location" : "\n"
- "Do you wish the installer to initialize Anaconda3 by running conda init": "yes"
否则,它们仅被视为该expect
部分的下一个参数。YAML 严重依赖于正确的缩进。