错误! Ansible中有冲突的动作语句(期望,命令) [英] ERROR! conflicting action statements (expect, command) in Ansible
问题描述
我正在尝试使用Ansible在多个主机上安装Java.
我寻找了expect
模块的一些示例来提供提示的答案.
我认为这种语法很好:
I'm trying to install java on several hosts with Ansible.
I looked for some examples of expect
module to provide answers to the prompts.
I think this syntax is quite fine:
- hosts: datanode
sudo: yes
sudo_user: root
tasks:
- expect:
name: install java jdk 7
command: apt-get install openjdk-7-jdk
responses:
Question:
'Do you want to continue? [Y/n]': 'Y'
但是当我尝试执行ansible-playbook file.yml
时,我收到错误消息:
But when I try to execute ansible-playbook file.yml
I receive the error:
ERROR! conflicting action statements (expect, command)
The error appears to have been in '/root/scp.yml': line 5, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- expect:
^ here
问题出在哪里? (我已经安装了ansible 2.0.1.0,pexpect,python)
Where is the problem? (I have installed ansible 2.0.1.0, pexpect, python)
谢谢!
推荐答案
注意,表明Ansible可与yaml文件一起使用,并且这类文件带有缩进的.这意味着您在每个语句之前放置的空格对于让Ansible了解它们是如何嵌套的非常重要. 有关yaml的详细信息.
NOTE that Ansible works with yaml files, and this kind of files are indented. This means that the spaces you put before each statement are important to let Ansible to understand how are they nested. More info about yaml.
更正的任务:
- hosts: datanode
sudo: yes
sudo_user: root
tasks:
- name: install java jdk 7
expect:
command: apt-get install openjdk-7-jdk
responses:
Question:
- 'Y'
- 'n'
这将避免您的语法错误.
This will avoid your syntax error.
来源: http://docs.ansible.com/ansible/expect_module.html
或者,如果您总是想对apt-get install
命令说是",则可以添加-y
参数:
Alternatively, if you always want to say "yes" to your apt-get install
commands, you can add the -y
argument:
apt-get install -y openjdk-7-jdk
或更妙的是,使用 apt
Ansible模块.
Or even better, use the apt
Ansible module.
这篇关于错误! Ansible中有冲突的动作语句(期望,命令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!