0

I am trying to set up rolling OS updates on linux systems using Ansible. My intention is to update the systems together but then reboot individually using the code below which includes a block section in which throttle: 1 is specified.

- when: (reboot_required is defined) and (allow_reboot)
  block:
    - when: reboot_required.rc != 0
      block:
        - name: "Advise of systems to be rebooted following an OS Update"
          ansible.builtin.debug:
            msg: "OS has been updated and reboot is now required and allowed by 'allow_reboot: True'"
        - name: Reboot the server if required
          ansible.builtin.shell: sleep 3; reboot
          ignore_errors: True
          changed_when: False
          async: 1
          poll: 0
        - name: Wait for the server to come back after reboot
          wait_for_connection:
            timeout: 600
            delay: 20
          register: reboot_result
        - name: Advise reboot time
          ansible.builtin.debug:
            msg: "The system rebooted in {{ reboot_result.elapsed }} seconds."
      throttle: 1

However, this seemed to run that entire block for all hosts in parallel still, looking at the console I saw all hosts go down around the same time together.

I can't use serial because that applies to the whole play so I use throttle to apply to just that block.

Any suggestions?

1 Answers1

0

I solved this by turfing out all the reboot tasks and replacing them just with the ansible.builtin.reboot module.

- when: reboot_required is defined and allow_reboot
  block:
    - when: reboot_required.rc != 0
      block:
        - name: "Advise of systems to be rebooted following an OS Update"
          ansible.builtin.debug:
            msg: "OS has been updated and reboot is now required and allowed by 'allow_reboot: True'"
        - name: Reboot host and wait for it to restart
          ansible.builtin.reboot:
            msg: "Reboot initiated by Ansible"
            connect_timeout: 5
            reboot_timeout: 600
            pre_reboot_delay: 0
            post_reboot_delay: 30
            test_command: whoami
          register: reboot_result
        - name: Advise reboot time
          ansible.builtin.debug:
            msg: "The system rebooted in {{ reboot_result.elapsed }} seconds."
      throttle: 1