Score:0

Rolling updates on Ansible using throttle

in flag

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?

anfieldroad avatar
in flag
I get the feeling that "async" setting may be where it is happening, I will test without that
Score:0
in flag

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
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.