Ansible Timeout (12s) waiting for privilege escala

2020-08-11 10:45发布

I'm having trouble running my Ansible playbook on AWS instance. Here is my version:

$ ansible --version
ansible 2.0.0.2

I created an inventory file as:

[my_ec2_instance]
default ansible_host=MY_EC2_ADDRESS ansible_user='ubuntu' ansible_ssh_private_key_file='/home/MY_USER/MY_KEYS/MY_KEY.pem'

Testing connection to my server:

$ ansible -i provisioner/inventory my_ec2_instance -m ping
default | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

Now when running my playbook on this inventory I get the error Timeout (12s) waiting for privilege escalation prompt as follows:

$ ansible-playbook -i provisioner/inventory -l my_ec2_instance provisioner/playbook.yml

PLAY [Ubuntu14/Python3/Postgres/Nginx/Gunicorn/Django stack] *****

TASK [setup] *******************************************************************
fatal: [default]: FAILED! => {"failed": true, "msg": "ERROR! Timeout (12s) waiting for privilege escalation prompt: "}

NO MORE HOSTS LEFT *************************************************************

PLAY RECAP *********************************************************************
default                    : ok=0    changed=0    unreachable=0    failed=1

If I run the same playbook using the .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory as the inventory parameter it works perfectly on my Vagrant instance.(I believe, proving there is nothing wrong in the playbook/roles itself)

Also, if I run it with an -vvvv, copy the exec ssh line and run it manually it indeed connects to AWS without problems.

Do I need to add any other parameter on my inventory file to connect an EC2 instance? What am I missing?

9条回答
趁早两清
2楼-- · 2020-08-11 10:57

I fixed this error for my system because I forgot I had altered the ansible config file:

sudo vim /etc/ansible/ansible.cfg 

Try commenting the priviledge parameters that could be trying to sudo to root.

like so:

[privilege_escalation]
#become=True
#become_method=su
#become_user=root
#become_ask_pass=False
#become_exe="sudo su -"

The account I was trying to ssh as did not have permission to become root.

查看更多
迷人小祖宗
3楼-- · 2020-08-11 11:00

In my case, the root cause was an incorrect entry in /etc/hosts for the localhost, causing a 20s delay for any sudo command.

127.0.0.1 wronghostname

Changed it to the correct hostname to fix it. No more delay for sudo/privileged commands.

查看更多
We Are One
4楼-- · 2020-08-11 11:04

Check if it is a problem with an old version of sudo at destination server. Some old sudo versions does not have the -n option ansible uses.

查看更多
贪生不怕死
5楼-- · 2020-08-11 11:05

There is a git issue about this error that affect various versions of Ansible 2.x in here https://github.com/ansible/ansible/issues/13278#issuecomment-216307695

My solution was simply to add timeout=30 to /etc/ansible/ansible.cfg.

This is not a "task" or "role" timeout and was enough to solve the error (I do have some roles/tasks that take much longer than that).

查看更多
Deceive 欺骗
6楼-- · 2020-08-11 11:11

I am building secure VM images for AWS, QEMU and VBox on an isolated network, with limited DNS support. Increasing the SSH Timeout to 40 sec had limited effect in my situation.

I am using Packer v1.5.5, Ansible v2.9.2 and OpenSSH v7.4p1

My solution was to change the UseDNS parameter in /etc/ssh/ssd_config to no.

I added the following lines in my RHEL/CentOS kickstart configuration, with great result.

%post
# Disable DNS lookups by sshd to address Ansible timeouts
perl -npe 's/^#UseDNS yes/UseDNS no/g' -i /etc/ssh/sshd_config
%end
查看更多
smile是对你的礼貌
7楼-- · 2020-08-11 11:18

I ran the command like follows & it works : command:

ansible-playbook -c paramiko httpd.yml
查看更多
登录 后发表回答