Trying to use wait_for to sequence a set of reboots

Not doing well.

It starts here: https://github.com/LeamHall/Ansible_Test/blob/master/playbooks/reboot_nodes.yml

  • hosts: b2532_vms

become: True

vars:

hosts:

  • genesis
  • exodus

roles:

- reboot

Which should call playbooks/roles/reboot/tasks/main.yml: https://github.com/LeamHall/Ansible_Test/blob/master/playbooks/roles/reboot/tasks/main.yml

  • name: reboot_and_wait_for

include: reboot_node.yml

include: wait_for.yml

include: debug.yml

with_items:

- "{{ hosts }}"

Which should call: https://github.com/LeamHall/Ansible_Test/blob/master/playbooks/roles/reboot/tasks/reboot_node.yml

  • name: reboot
command: /sbin/reboot

But doesn’t. It does call the debug.yml file which just says “Hello there!”

Ideas? The goal is to reboot and wait_for each host in turn.

Leam

You can't have 3 includes in 1 task, you will need to split them into 3 separate tasks.

Kai, thanks! The issue is that I’m really struggling to get the “wait_for” to work. I need to have the rebooted machine up before I boot the next one. Any good pointers to docs? Ansible docs say it can be done but don’t seem to show you how.

Leam

This is about the best I have so far. When I tried to put the duplicate tasks into a role it didn’t work. May try an “include_tasks” after a nap.

https://github.com/LeamHall/Ansible_Test/blob/master/playbooks/reboot_nodes.yml

what I’m using as part of a (multi-hosts) play:

Task one is to async trigger the reboot
Task two the wait for ssh to come back (for each host in the play)

  • name: Reboot the system
    shell: sleep 2 && shutdown -r now “Ansible reboot triggered”
    become: True
    async: 1
    poll: 0
    ignore_errors: true

FixMe: Trigger the wait for ssh on all the targets (long operation)

  • name: waiting for server to come back
    wait_for:
    host: “{{ inventory_hostname }}”
    port: 22
    delay: 15
    timeout: 1200
    connect_timeout: 15
    state: started
    delegate_to: localhost