ec2实例的Ansible wait_for连接超时

时间:2017-11-21 09:40:18

标签: amazon-ec2 ansible

- hosts: "tag_deployment_group_{{ env }}_{{ app }}"
  gather_facts: false
  remote_user: root
  tasks:
 - name: "wait for instances to boot up"
   wait_for: port=22 delay=30 connect_timeout=300 search_regex=OpenSSH state=started
 - name: "copy cron script"
   hosts: "tag_deployment_group_{{ env }}_{{ app }}"
   copy: src=/etc/ansible/files/script.sh dest=/root/scripts/script.sh
<10.0.0.1> SSH: EXEC ssh -C -o ControlMaster=auto -o 
ControlPersist=60s -o KbdInteractiveAuthentication=no -o 
PreferredAuthentications=gssapi-with-mic,gssapi-
keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o 
ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/c7f4018000 -tt 
10.0.0.1> '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-
tmp-1511255180.71-122270830456576/wait_for.py; rm -rf 
"/root/.ansible/tmp/ansible-tmp-1511255180.71-122270830456576/" > 
/dev/null 2>&1 && sleep 0'"'"''
<10.0.0.2> (255, '', 'ssh: connect to host 10.0.0.2 port 22: 
Connection timed out\r\n')
fatal: [10.0.0.2]: UNREACHABLE! => {
"changed": false, 
"msg": "Failed to connect to the host via ssh: ssh: connect to host 
10.0.0.2 port 22: Connection timed out\r\n", 
"unreachable": true
}
<10.0.0.1> (0, '\r\n{"elapsed": 30, "search_regex": "OpenSSH", 
"state": "started", "invocation": {"module_args": 
{"active_connection_states": ["ESTABLISHED", "FIN_WAIT1", "FIN_WAIT2", 
"SYN_RECV", "SYN_SENT", "TIME_WAIT"], "state": "started", "port": 22, 
"delay": 30, "search_regex": "OpenSSH", "host": "127.0.0.1", "sleep": 
1, "timeout": 300, "exclude_hosts": null, "msg": null, "path": null, 
"connect_timeout": 300}}, "path": null, "port": 22}\r\n', 'Shared 
connection to 10.0.0.1 closed.\r\n')
ok: [10.0.0.1] => {
"changed": false, 
"elapsed": 30, 
"failed": false, 
"invocation": {
    "module_args": {
        "active_connection_states": [
            "ESTABLISHED", 
            "FIN_WAIT1", 
            "FIN_WAIT2", 
            "SYN_RECV", 
            "SYN_SENT", 
            "TIME_WAIT"
        ], 
        "connect_timeout": 300, 
        "delay": 30, 
        "exclude_hosts": null, 
        "host": "127.0.0.1", 
        "msg": null, 
        "path": null, 
        "port": 22, 
        "search_regex": "OpenSSH", 
        "sleep": 1, 
        "state": "started", 
        "timeout": 300
    }
}, 
"path": null, 
"port": 22, 
"search_regex": "OpenSSH", 
"state": "started"

我正在尝试启动几个实例并在实例上执行任务,出于某种原因,我的Ansible playbook在ec2实例启动后的一个实例的wait_for模块中失败。

我尝试了不同的connect_timeout,但我不认为它等待300秒。

1 个答案:

答案 0 :(得分:2)

因为您尝试在要“等待”的同一台计算机上执行该模块。由于它不可用,上传和运行模块所需的连接失败(这就是为什么它不等待指定的超时)。

添加delegate_to: localhost / connection: local或改为使用wait_for_connection module