11

I am trying to run a "folder creation" command with my ansible playbook. (Code is below)

The creation requires sudo login to execute.

I run the playbook as follows:

ansible-playbook myfile.yml --ask-pass

This prompts for user account password of remote machine. The ssh connection gets established, but commands fail with permission denied since its not taking super user password.

How can I fix my issue?

 hosts: GSP
 tasks:
   - name: "make build directory"
     command: mkdir -p /home/build/
     become: true
     become_user: root
   - name: "change permissions on the directory"
     command: chmod 777 -R /home/
     become: true
     become_user: root
Joe Cove
  • 7
  • 3
Suzanno Hogwarts
  • 323
  • 2
  • 3
  • 12

2 Answers2

9

There's also --ask-become-pass switch for ansible-playbook cli to query user for sudo password.

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • 1
    hi I tried with this option,but somehow the playbook is getting stuck,i guess waiting for sudo password. EXEC /bin/sh -c 'sudo -H -S -p "[sudo via ansible, key=xeimypdogbjjpjsufkwnrveykjyqqbsu] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-xeimypdogbjjpjsufkwnrveykjyqqbsu; /usr/bin/python /home/atsuser/.ansible/tmp/ansible-tmp-1504858247.495368-256432984211520/command.py; rm -rf "/home/atsuser/.ansible/tmp/ansible-tmp-1504858247.495368-256432984211520/" > /dev/null 2>&1'"'"' && sleep 0' – Suzanno Hogwarts Sep 08 '17 at 08:22
2

You can add the ansible_become_pass variable to specify the become password in your playbook.

More details can be found here: http://docs.ansible.com/ansible/latest/become.html

sys0dm1n
  • 819
  • 6
  • 13