Reputation: 3067
I'm trying to run an ansible playbook and after gathering facts, Ansible pauses on the first task which should take less than a second and won't move on. What are some things that I can check? I've tried:
Upvotes: 4
Views: 5687
Reputation: 882
A possible source of the problem could be related to https://github.com/ansible/ansible/issues/30411, which is a bug report of Ansible hanging ifinitely. No output is shown where exactly Ansible is hanging. Following this Github issue, the problem itself is not in Ansible but rather on the target host(s) Ansible currently connects to (e.g. non-working df due to unavailable mount). This just happened to me today when running a playbook on a large group of targets and Ansible would just hang without further information. I came across the Github issue and eventually found the problematic target host; yes, it was a hanging NFS mount.
Upvotes: 0
Reputation: 469
My two cents - Passwordless sudo may not be a proper solution as in most cases the nodes are sudo password protected. It is a best practice to use sudo password in the playbook as a variable and pass the value from a config file and this config file can be encrypted using ansible-vault.
Upvotes: 0
Reputation: 5433
Your playbook hangs as it is performing some kind of task that needs credentials.You must have to specify the the user inside the playbook which must be used when running the playbook it should look something like this
hosts: thinkingmonster
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
– name: ensure apache is installed
yum: pkg=httpd state=latest
– name: place configuration file
template: src=/etc/httpd/conf/httpd.conf dest=/etc/httpd.conf
notify:
– restart apache
– name: ensure apache is running
service: name=httpd state=started enabled=yes
handlers:
– name: restart apache
service: name=httpd state=restarted
Check i have used remote user as root.But if you are not specifying this in the playbook then you have to pass the same on command line when running your playbook as
ansible-playbook <your-playbook-name> -u <user> -k <password>
and if sudo user is required to perform the task then
ansible-playbook <your-playbook-name> -u <user> -k <password> --sudo -K
Upvotes: 0
Reputation: 714
Ansible, by default, will block in cases where ssh-the-command-line would block. Occasionally this can bite you, if you're pushing to a great deal of servers and one of the logins failed and is asking for your private-key password or something goofy. Running your playbooks like so:
ANSIBLE_SSH_ARGS="-o BatchMode=yes" ansible-playbook -i inventory/foo playbook.yml
should just make ssh fail instead of prompting you.
Upvotes: 0
Reputation: 7412
try "-k" options and system must have the sshpass installed
ansible servers -vvvv -m ping -i inventory -u vagrant -k
The output
SSH password: <<USEr PASSWORD>>
The console Output of the verbose
<precise32> ESTABLISH CONNECTION FOR USER: vagrant
<precise32> REMOTE_MODULE ping
<precise32> EXEC ['sshpass', '-d6', 'ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'GSSAPIAuthentication=no', '-o', 'PubkeyAuthentication=no', '-o', 'ConnectTimeout=10', 'precise32', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1423020915.88-101376543892740 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1423020915.88-101376543892740 && echo $HOME/.ansible/tmp/ansible-tmp-1423020915.88-101376543892740'"]
<precise32> PUT /tmp/tmpNGxttI TO /home/vagrant/.ansible/tmp/ansible-tmp-1423020915.88-101376543892740/ping
<precise32> EXEC ['sshpass', '-d6', 'ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'GSSAPIAuthentication=no', '-o', 'PubkeyAuthentication=no', '-o', 'ConnectTimeout=10', 'precise32', u"/bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1423020915.88-101376543892740/ping; rm -rf /home/vagrant/.ansible/tmp/ansible-tmp-1423020915.88-101376543892740/ >/dev/null 2>&1'"]
The final Output
precise32 | success >> {
"changed": false,
"ping": "pong"
}
Upvotes: 0
Reputation: 51
You don't NEED passwordless sudo, you just need to match your options to your sudo environment. If you need to provide a sudo password you can just add -K (--ask-sudo-pass) to your ansible invocation.
Upvotes: 5
Reputation: 3067
Found out I needed passwordless sudo.. I changed /etc/sudoers:
%admin ALL=(ALL) NOPASSWD:ALL
Upvotes: 0