Reputation: 4590
I am using ansible apt module apt in my playbook. It asks for a user prompt and I want to provide "Y". Could some one please tell how this can be done. I used "expect" but it doesn't work.
- 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'
And I get below error
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"}
Upvotes: 1
Views: 3478
Reputation: 3193
You can not use the expect
module as a wrapper around other modules (I assume that is what you are trying to do). The expect module
executes a command and responds to prompts The given command will be executed on all selected nodes.
You are getting the 'item' is undefined
error message because the when
clause has wrong indention. But that wouldn't work anyway. See above.
You can use playbooks prompts in your playbook and that is the only way Ansible will prompt the user for input I'm aware of.
If you just want to make sure that the latest version of a package is installed on a system using apt package manager use this:
- name: Install latest apparmor packages - xxx-policy
apt:
name: "xaz-policy"
state: latest
update_cache: true
Upvotes: 1