重新启动2.1.1.0失败

我一直在试图创build一个非常简单的Ansible操作手册,它将重新启动服务器并等待它回来。

我曾经在Ansible 1.9上使用过,但是我最近升级到了2.1.1.0,并且失败了。

我正在重新启动的主机叫做idm,IP地址是192.168.200.23。

正在使用命令从我的主机192.168.200.1运行剧本

$ ansible-playbook reboot.yml -vvvv 

这是我正在使用的剧本

 --- - hosts: idm tasks: - name: Restart server become: yes shell: sleep 2 && /sbin/shutdown -r now "Ansible system package upgraded" - name: waiting 60 secs for server to come back local_action: wait_for host=192.168.200.23 port=22 delay=60 connect_timeout=200 become: false 

它重新启动机器罚款,但几乎立即失败

 <192.168.200.23> ESTABLISH SSH CONNECTION FOR USER: root <192.168.200.23> SSH: EXEC ssh -C -vvv -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=/home/myork/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.200.23 '/bin/sh -c '"'"'LANG=en_GB.UTF-8 LC_ALL=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1472242630.58-176546106960362/command; rm -rf "/root/.ansible/tmp/ansible-tmp-1472242630.58-176546106960362/" > /dev/null 2>&1 && sleep 0'"'"'' fatal: [idm]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true} 

任何想法,我在这里错过了?

谢谢!

Solutions Collecting From Web of "重新启动2.1.1.0失败"

我用async fire和forget模式重启服务器:

 - name: Restart server become: yes shell: sleep 2 && /sbin/shutdown -r now "Ansible system package upgraded" async: 1 poll: 0 

下面的代码从康斯坦丁完美地工作。

 - name: Restart server become: yes shell: sleep 2 && /sbin/shutdown -r now "Ansible system package upgraded" async: 1 poll: 0 - name: waiting 60 secs for server to come back local_action: wait_for host=192.168.200.23 port=22 delay=20 connect_timeout=200 become: false delegate_to: 127.0.0.1 

更新与@Konstantin苏沃洛夫的评论。

这里有一个更好的解决方案来避免硬IP

 - name: Restart server shell: /sbin/shutdown -r now "Ansible system package upgraded" async: 1 poll: 0 - set_fact: wait_host="{{ ansible_host }}" - name: Wait for server to come back local_action: wait_for host={{wait_host}} delay=20 port=22 state=started become: false 

埃里克