Ansible 1.9.1 'become' and sudo issue Ansible 1.9.1 'become' and sudo issue bash bash

Ansible 1.9.1 'become' and sudo issue


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:

---- hosts: all  sudo: yes  gather_facts: no  tasks:  - name: "sudo to root"    command: /usr/bin/whoami

2) new become

---- hosts: all  become: yes  become_method: sudo  gather_facts: no  tasks:  - name: "sudo to root"    command: /usr/bin/whoami

3) using ansible.cfg:

[privilege_escalation]become = yesbecome_method = sudo

and then in a playbook:

---- 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:

  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


I think you should use the sudo directive in the hosts section so that subsequent tasks can run with sudo privileges unless you explicitly specified sudo:no in a task.

Here's your playbook that I've modified to use sudo directive.

# Checks the hosts provisioned by midrange---- hosts: all  sudo: yes  gather_facts: no  tasks:    - name: "sudo to configued user -- tstuser01"      command: /usr/bin/whoami