I'm seeing an error message when I try to run a task with sudo in my Ansible playbook.
Here's my playbook:
---
- hosts: production
gather_facts: no
remote_user: deployer
become: yes
become_method: sudo
become_user: root
tasks:
- name: Whoami
command: /usr/bin/whoami
I would expect whoami to be root
but the task fails with the error message:
» ansible-playbook -i ansible_hosts sudo.yml --ask-sudo-pass
SUDO password: [I paste my sudo password here]
PLAY [production] *************************************************************
GATHERING FACTS ***************************************************************
fatal: [MY.IP] => Missing become password
TASK: [Whoami] ****************************************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
When I manually ssh into the box and try to sudo it works as expected:
» ssh deployer@production
» sudo whoami
[I paste the same sudo password]
root
The deployer user password was set by Ansible as follows (in a different playbook):
- hosts: production
remote_user: root
# The {{ansible_become_pass}} comes from this file:
vars_files:
- ./config.yml
tasks:
- name: Create deployer user
user: name=deployer uid=1040 groups=sudo,deployer shell=/bin/bash password={{ansible_become_pass}}
Where {{ansible_become_pass}}
is the password I desire hashed with the following python snippet:
python -c 'import crypt; print crypt.crypt("password I desire", "$1$SomeSalt$")'
"password I desire"
is replace with a password and "$1$SomeSalt$"
is a random salt.
I'm using Ansible version 1.9.4.
What's the problem?