I’m trying to understand how async interacts with networking devices such as Cisco switches. In my task below, I have async configured for two sets of commands that I want to run on specific models of switches. The problem therein lies with the amount of time it takes the first task to execute before proceeding to the next task. Which brought me to async.
Ideally, I would like both of the tasks to run simultaneously. And afterwards async_status to verify that these tasks completed without error.
With async_status set, should I delegate to localhost to check for the job_id? Has anyone had success with this?
- name: Upgrade switches using install add
cisco.ios.ios_command:
commands:
- command: 'install add file flash:{{ models[ansible_net_model]["ios_binary"] }} activate commit'
prompt: 'This operation may require a reload of the system. Do you want to proceed?'
answer: 'y'
async: 1800
poll: 0
when:
- models[ansible_net_model]["ios_md5"] in md5_result.stdout[0]
- ansible_net_model in ['C9200L-24P-4G', 'C9200L-48P-4G', 'C9300X-12Y']
tags:
- boot
register: install_add_task
- name: Upgrade switches using request platform
cisco.ios.ios_command:
commands:
- command: 'request platform software package install switch all file flash:{{ models[ansible_net_model]["ios_binary"] }} new auto-copy'
- command: 'reload'
prompt: 'Proceed with reload?'
answer: "\r"
async: 1800
poll: 0
when:
- models[ansible_net_model]["ios_md5"] in md5_result.stdout[0]
- ansible_net_model in ['C9300-24U', 'C9300-48U', 'C9500-16X', 'WS-C3850-24P', 'WS-C3850-48P', 'WS-C3850-12S', 'WS-C3850-24XS', 'WS-C3850-24U', 'WS-C3850-48U']
tags:
- boot
register: request_platform_task
- name: Wait for Upgrade tasks to complete
any_errors_fatal: true
ansible.builtin.async_status:
jid: "{{ item }}"
register: async_result
until: async_result.finished
retries: 100
delay: 1
with_items:
- install_add_task.ansible_job_id
- request_platform_task.ansible_job_id