Can't make Ansible to wait for a server to reboot and continue playbook to work

I am creating a playbook to install a software and I need to restart the server int he middle of the playbook.

I need my Ansible host to wait till the server is back and execute the rest of my tasks but this is not happenning.

These are my Ansible tasks related to reboot and wait:

... - name: restart server   shell: shutdown -r now   async: 1   poll: 0   become: yes   become_method: sudo   ignore_errors: true - name: waiting for server to come back after reboot   local_action: wait_for host={{ ansible_ssh_host }} state=started port=22 delay=30 timeout=300 connect_timeout=15 .... 

This is the output of running my playbook:

...  TASK [restart server] ********************************************************** fatal: [X.X.X.X]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}     to retry, use: --limit @ansible_pb.retry  PLAY RECAP ********************************************************************* X.X.X.X               : ok=2    changed=0    unreachable=1    failed=0 

Any idea what is wrong and how can I fix it?

Replay

This is a commonly known problem. See Reboot a server and wait for it to come back. Since Ansible 1.9.4 SSH loses connection before proceeding to the next task.

You need to add a delay (sleep) before the shutdown command:

- name: restart server
  shell: sleep 2 && shutdown -r now
  async: 1
  poll: 0
  become: yes
  become_method: sudo
  ignore_errors: true
- name: waiting for server to come back after reboot
  local_action: wait_for host={{ ansible_ssh_host }} state=started port=22 delay=30 timeout=300 connect_timeout=15
....

Category: ansible Time: 2016-07-29 Views: 0
Tags: ansible

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.249 (s). 12 q(s)