使用节流阀在 Ansible 上进行滚动更新

使用节流阀在 Ansible 上进行滚动更新

我正在尝试使用 Ansible 在 Linux 系统上设置滚动操作系统更新。我的目的是一起更新系统,然后使用下面的代码单独重新启动,其中包括一个指定了 throttle: 1 的块部分。

- 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

但是,这似乎仍然为所有主机并行运行整个块,查看控制台时我看到所有主机大约在同一时间一起关闭。

我不能使用串行,因为它适用于整个游戏,所以我使用节流阀来应用于该块。

有什么建议么?

答案1

我通过放弃所有重启任务并用 ansible.builtin.reboot 模块替换它们来解决这个问题。

- 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

相关内容