【问题标题】:ERROR! conflicting action statements (expect, command) in Ansible错误! Ansible 中的冲突操作语句(期望、命令)
【发布时间】:2016-04-19 18:51:57
【问题描述】:

我正在尝试使用 Ansible 在多个主机上安装 java。 我寻找了一些expect 模块的例子来提供提示的答案。 我认为这种语法很好:

- 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 时,我收到了错误:

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)

谢谢!

【问题讨论】:

  • 当 Ansible 明显抛出语法错误时,是什么让您认为语法“很好”?

标签: ansible expect ansible-playbook ansible-2.x


【解决方案1】:

注意 Ansible 可以处理 yaml 文件,并且这种文件是缩进的。这意味着您在每个语句之前放置的空格对于让 Ansible 了解它们是如何嵌套的很重要。 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'

这将避免您的语法错误。

来源:http://docs.ansible.com/ansible/expect_module.html

或者,如果您总是想对您的apt-get install 命令说“是”,您可以添加-y 参数:

apt-get install -y openjdk-7-jdk

或者更好的是,使用apt Ansible module

【讨论】:

  • @Héctor Valverde Pareja 我们如何将 expect 模块与 ansible apt 模块一起使用。你能举个例子吗?我在安装过程中收到提示,我想提供“Y”。我正在使用 apt 模块来安装软件包。
猜你喜欢
  • 2022-11-03
  • 2015-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-02
  • 2023-03-14
相关资源
最近更新 更多