How to handle upgrading of High Availability pair instances

I’m writing ansible-playbook to upgrade NetScaler High Availability pair.

Basically, there are two instances primary and secondary.
The process to upgrade manually is:

  • First we upgrade the secondary instance and than it reboots (as part of upgrade command),
  • Secondly, we upgrade the secondary instance and reboots

Currently, I’m using Ansible’s async option to run the upgrade command on secondary and waiting for it to come up, after upgrade(and reboot), later I’m repeating the same for the other node (or instance).

But another thing is that, the python gets removed during the upgrade and gets reinstalled, so in that case the async task(upgrade task) exits without further continuing.

Here is the link to the ansible-playbook: automation-toolkit/golden_templates/upgrade-netscaler/high-availability/normal-mode/ha_upgrade.yaml at main · netscaler/automation-toolkit · GitHub

Is there a better way I can handle this scenerio.

Any help would be appreciated.