понедельник, 3 октября 2016 г.

Shutdown server and wait till the connection is down with ansible

When executing something like "ansible all -m command -a "shutdown now" --ask-pass -b" on ubuntu server 16 ansible will power off the machine, but return the error 

192.168.0.2 | FAILED | rc=0 >>
MODULE FAILURE  
                        


The solution is to add the delay before shutdown command using shell module and sleep.

shutdown.yml:
 
---
- hosts: all
  tasks:
  - name: shutdown
    shell: nohup bash -c "sleep 2s && shutdown now" &
    async: 0
    poll: 0
    ignore_errors: true
    become: true

  - name: wait for server power off
    local_action: wait_for host="{{ inventory_hostname }}"
      state=stopped port=22 delay=10 timeout=300
    become: false


Wait for server fower off task will check that at least ssh on the host is down. But it will not notify if shutdown itself hangs.

Комментариев нет:

Отправить комментарий