This is my simple playbook,
---
- name: test
hosts: all
tasks:
- name: testing
shell: /usr/bin/whoami
register: testing
- name: show the result
debug:
msg: "{{ testing.stdout }}"
When I try to use this using user1 I get correct the expected output as user1.
However, my requirement is to run the shell command using a root user. something like sudo whoami. So I modified the playbook like this.
---
- name: test
hosts: all
tasks:
- name: testing
shell: /usr/bin/whoami
become: true
register: testing
- name: show the result
debug:
msg: "{{ testing.stdout }}"
However, I keep getting following error,
fatal: [xxxxxxxxx]: FAILED! => {
"msg": "Missing sudo password"
}
Can anybody please help understand what I am missing here?
To allow the user1 to run this as sudo root, I have added following entry in the sudoers file.
user1 ALL=(ALL:ALL) /usr/bin/whoami
Also, to avoid the providing user1 password, I added following entry to the local ansible.cfg
[privilege_escalation]
become_ask_pass=False
Still getting the same error mentioned above.
An example playbook
with an output of
shows with
sudo tail -F /var/log/secureon the Remote NodeTo Summarize
The command executed in the example was
Therefore you could try to add in
sudoersfile a line at the end, like intail -1 /etc/sudoersand under
/ect/sudoers.da file/etc/sudoers.d/ansiblefor Ansible Modules written in Python.
Further Reading
sudoersfile?