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.
shellmodule, hence why Ansible specifically explain that privilege escalation must be general.user1 ALL=(ALL) NOPASSWD: ALL