Question:
I am trying to run an extremely simple playbook to test a new Ansible setup.
When using the ‘new’ Ansible Privilege Escalation config options in my ansible.cfg file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[defaults] host_key_checking=false log_path=./logs/ansible.log executable=/bin/bash #callback_plugins=./lib/callback_plugins ###### [privilege_escalation] become=True become_method='sudo' become_user='tstuser01' become_ask_pass=False [ssh_connection] scp_if_ssh=True |
I get the following error:
1 2 3 4 |
fatal: [webserver1.local] => Internal Error: this module does not support running commands via 'sudo' FATAL: all hosts have already failed -- aborting |
The playbook is also very simple:
1 2 3 4 5 6 7 8 9 10 |
# Checks the hosts provisioned by midrange --- - name: Test su connecting as current user hosts: all gather_facts: no tasks: - name: "sudo to configued user -- tstuser01" #action: ping command: /usr/bin/whoami |
I am not sure if there is something broken in Ansible 1.9.1 or if I am doing something wrong. Surely the ‘command’ module in Ansible allows running commands as sudo.
Answer:
The issue is with configuration; I also took it as an example and got the same problem. After playing awhile I noticed that the following works:
1) deprecated sudo
:
1 2 3 4 5 6 7 8 |
--- - hosts: all sudo: yes gather_facts: no tasks: - name: "sudo to root" command: /usr/bin/whoami |
2) new become
1 2 3 4 5 6 7 8 9 |
--- - hosts: all become: yes become_method: sudo gather_facts: no tasks: - name: "sudo to root" command: /usr/bin/whoami |
3) using ansible.cfg:
1 2 3 4 |
[privilege_escalation] become = yes become_method = sudo |
and then in a playbook:
1 2 3 4 5 6 7 |
--- - hosts: all gather_facts: no tasks: - name: "sudo to root" command: /usr/bin/whoami |
since you “becoming” tstuser01 (not a root like me), please play a bit, probably user name should not be quoted too:
1 2 |
become_user = tstuser01 |
at least this is the way I define remote_user in ansible.cfg and it works… My issue resolved, hope yours too