我在AWS实例上运行Ansible playbook时遇到了麻烦。这是我的版本:
$ ansible --version
ansible 2.0.0.2
我创建了一个库存文件:
[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'
测试与我的服务器的连接:
$ ansible -i provisioner/inventory my_ec2_instance -m ping
default | SUCCESS => {
"changed": false,
"ping": "pong"
}
现在,当我在这个库存上运行我的剧本时,我得到错误Timeout (12s) waiting for privilege escalation prompt
如下:
$ 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
如果我使用.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
作为库存参数运行相同的剧本,它在我的Vagrant实例上完美运行。(我相信,证明剧本/角色本身没有错)
此外,如果我使用-vvvv
运行它,复制exec ssh
行并手动运行它确实连接到AWS没有问题。
我是否需要在库存文件中添加任何其他参数来连接EC2实例?我错过了什么?
这个错误有一个git问题影响了这里https://github.com/ansible/ansible/issues/13278#issuecomment-216307695的各种版本的Ansible 2.x.
我的解决方案只是将timeout=30
添加到/etc/ansible/ansible.cfg
。
这不是“任务”或“角色”超时,并且足以解决错误(我确实有一些角色/任务需要比这更长的时间)。
有时设置阶段需要更多时间用于ec2实例,您需要将ansible.cfg中的超时值更改为timeout=40
。这会将超时值设置为40秒。
检查目标服务器上的旧版sudo是否存在问题。一些旧的sudo版本没有-n选项ansible使用。
我为我的系统修复了这个错误,因为我忘了我已经改变了ansible配置文件:
sudo vim /etc/ansible/ansible.cfg
尝试评论可能尝试sudo到root的priviledge参数。
像这样:
[privilege_escalation]
#become=True
#become_method=su
#become_user=root
#become_ask_pass=False
#become_exe="sudo su -"
我试图ssh的帐户没有成为root用户的权限。
在目标计算机上运行它
sudo apt-get install python-simplejson
我运行命令,如下所示&它的工作原理:命令:
ansible-playbook -c paramiko httpd.yml