Hi - I’m new to Ansible and struggling
I have 2 playbooks for training/demo purposes. One to install Tree and Nano and another to remove them again. My control and destination servers are both Centos7
My webservers_latest.yml playbook for installing is…
I should add that this is Ansible 1.9.4
Brian_Coca
(Brian Coca)
January 14, 2016, 5:13pm
3
can you run both with -vvvv to see what Ansible is doing? also show
the command line invocation of both playbooks.
Hi Brian
from /etc/ansible I am running ansible-playbook webservers_absent.yml
with -vvvv I get
SUDO password:
PLAY [webservers] *************************************************************
GATHERING FACTS ***************************************************************
<myuser@ipaddress > ESTABLISH CONNECTION FOR USER: myuser
<myuser@ipaddress > REMOTE_MODULE setup
<myuser@ipaddress > EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/myuser /.ansible/cp/ansible-ssh-%h-%p-%r” -o IdentityFile=“/home/myuser /.ssh/id_rsa” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1452847308.18-48037085136110 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1452847308.18-48037085136110 && echo $HOME/.ansible/tmp/ansible-tmp-1452847308.18-48037085136110’
<myuser@ipaddress > PUT /tmp/tmp4cBgiH TO /home/myuser /.ansible/tmp/ansible-tmp-1452847308.18-48037085136110/setup
<myuser@ipaddress > EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/myuser /.ansible/cp/ansible-ssh-%h-%p-%r” -o IdentityFile=“/home/myuser /.ssh/id_rsa” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 /bin/sh -c ‘LANG=C LC_CTYPE=C /usr/bin/python /home/myuser/.ansible/tmp/ansible-tmp-1452847308.18-48037085136110/setup; rm -rf /home/myuser /.ansible/tmp/ansible-tmp-1452847308.18-48037085136110/ >/dev/null 2>&1’
ok: [myuser@ipaddress ]
TASK: [ensure tree is absent] *************************************************
<myuser@ipaddress > ESTABLISH CONNECTION FOR USER: myuser
<myuser@ipaddress > REMOTE_MODULE yum name=tree state=absent
<myuser@ipaddress > EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/myuser /.ansible/cp/ansible-ssh-%h-%p-%r” -o IdentityFile=“/home/myuser/.ssh/id_rsa” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1452847335.31-110782753766308 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1452847335.31-110782753766308 && echo $HOME/.ansible/tmp/ansible-tmp-1452847335.31-110782753766308’
myuser@ipaddress PUT /tmp/tmpXyPW7R TO /home/myuser /.ansible/tmp/ansible-tmp-1452847335.31-110782753766308/yum
<myuser@ipaddress > EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/myuser /.ansible/cp/ansible-ssh-%h-%p-%r” -o IdentityFile=“/home/myuser /.ssh/id_rsa” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 /bin/sh -c ‘LANG=C LC_CTYPE=C /usr/bin/python -tt /home/myuser/.ansible/tmp/ansible-tmp-1452847335.31-110782753766308/yum; rm -rf /home/myuser /.ansible/tmp/ansible-tmp-1452847335.31-110782753766308/ >/dev/null 2>&1’
failed: [myuser@ipaddress ] => {“changed”: false, “failed”: true, “rc”: 1, “results”: [“Loaded plugins: fastestmirror\n”]}
msg: You need to be root to perform this command.
FATAL: all hosts have already failed – aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/home/myuser /webservers_absent.retry
myuser@ipaddress : ok=1 changed=0 unreachable=0 failed=1
myuser and ipaddress are redacted
Regards
Paul
Brian_Coca
(Brian Coca)
January 15, 2016, 3:04pm
5
how are you telling it to prompt for passwords? where are you setting
it to use sudo?
note that prompting for sudo password does NOT imply sudo will be used.
SFT
(SFT-)
January 16, 2016, 1:25pm
6
Run with -K option as per man page. This will prompt you for sudo password.
you probably want “sudo: yes” above the tasks … ?
Alex
Hi - this resolved it and makes sense but I don’t understand why I didn’t need this line in my install script
It was only a demo so I won’t be spending any more time on it
thanks all
You are awesome ! After about half a day of search this one solved it !
Hi paul - What is the solution ?
Enable below parameters in ansible.cfg and then try
vi /etc/ansible/ansible.cfg
[defaults]
inventory=hosts(file)
[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False