Automation

6Oct

Using Reboot Module in Ansible 2.7

For a while, rebooting a Linux machine using Ansible has been done primarily using a combination of a reboot shell command module and a wait_for clause to pause execution of other tasks until that machine has came back up. This is also the method that is being taught at the current available revision of DO407 Automation with Ansible course by Red Hat (based on Ansible 2.3). Using this method can be done as follows:

---
- name: Reboot and wait until the server is up
  hosts: server1
  tasks:

    - name: reboot machine
      shell: sleep 2; shutdown -r now "Ansible triggered reboot"
      async: 1
      poll: 0
      ignore_errors: true

    - name: Wait for server to come back
      wait_for:
        host: "{{ inventory_hostname }}"
        state: started
        delay: 30
        timeout: 300
        port: 22
      delegate_to: localhost

New in Ansible 2.7: reboot module

Read More »

Written with love ♥