错误!Ansible 中的冲突动作语句(expect、command) [英] ERROR! conflicting action statements (expect, command) in Ansible

查看:27
本文介绍了错误!Ansible 中的冲突动作语句(expect、command)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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 中的冲突动作语句(expect、command)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆