apt模块中的Ansible用户提示 - 无法传递值“是”

时间:2016-07-27 12:31:17

标签: ansible expect ansible-playbook apt

我在我的剧本中使用了ansible apt模块apt。它要求用户提示,我想提供“Y”。有人可以告诉我们如何做到这一点。我用“期待”但它不起作用。

- name: Install latest apparmor packages - xxx-policy
  expect:
    apt: pkg={{ item.name }}={{ item.deb_version }} update_cache=yes state=present force=yes
    with_items: { name: 'xaz-policy', deb_version: '{{ apparmor.xxx_policy.deb_version }}'}
    when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
    responses:
      Question:
        - 'Y'

我得到以下错误

TASK [Install latest apparmor packages - xxx-policy] ************************    task path:    /home/jenkins/workspace/OSInnovationB/docker_upgradation_job/playbooks/tasks/test.yml:47 fatal: [xxx-xxx-host-01]: FAILED! => {"failed": true, "msg": "'item' is undefined"}

1 个答案:

答案 0 :(得分:1)

您不能将expect模块用作其他模块的包装器(我假设您正在尝试这样做)。 expect module

  

执行命令并响应提示将在所有选定节点上执行给定命令。

您收到'item' is undefined错误消息,因为when子句有错误的缩进。但这无论如何都行不通。见上文。

你可以在你的剧本中使用playbooks prompts,这是Ansible提示用户输入我知道的唯一方法。

如果您只是想确保使用apt包管理器在系统上安装最新版本的软件包,请使用以下命令:

- name: Install latest apparmor packages - xxx-policy
  apt:
    name: "xaz-policy"
    state: latest
    update_cache: true
相关问题