'How do I agree to install the package?
My playbook:
- name: "install software"
hosts: local
connection: local
tasks:
- name: install git
expect:
command: yum install git
responses:
Is this ok [y/d/N]: 'y'
I execute the command sudo ansible-playbook test.yaml, but I get an error.
Total download size: 4.5 M
Installed size: 22 M
Is this ok [y/d/N]:
MSG:
non-zero return code
Solution 1:[1]
One way would be to avoid the expect module entirely and use the yum module instead
- name: Install git
yum:
name: git
state: latest
This way, it will autoaccept
For expect module maybe you could try this.
responses:
(.*)Is this ok(.*): 'y'
Solution 2:[2]
Whereby the currently accepted answer is the preferred and recommend solution, the command line parameter to agree on installation is according man yum
-y, --assumeyes Assume yes; assume that the answer to any question which would be asked is yes. Configuration Option: assumeyes
Therefore the task would be
- name: Install Git via 'yum'
shell:
cmd: yum --assumeyes install git
warn: false
register: result
Further Q&A
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tolis Gerodimos |
| Solution 2 | U880D |
