05-12-2023 03:55 PM
Hi dear community,
May i ask you to review the code below and advise how to prevent the router from downloading new software if it is already in flash:
# Check if IOS is already present in the flash
- name: Check if IOS is already present on the flash
ios_command:
commands:
- command: "dir flash: | include {{ new_ios_bin }}"
register: dir_flash
tags:
- flash
with_items:
- "{{ device_name.msg }}"
loop_control:
index_var: item
vars:
ansible_host: "{{ device_name.msg[item].Name }}"
# Display content of previously registered value
- debug:
var: dir_flash
# Copy of IOS software on remote device
- name: Copy of IOS software on remote device
ios_command:
commands:
- command: "copy tftp://{{ tftp_server }}/{{ tftp_path }}/{{ new_ios_bin }} bootflash:"
prompt: '[{{ new_ios_bin }}]'
answer: "\r"
when:
- ansible_net_model != ["upgrade_ios_version"]
- new_ios_bin not in ["dir_flash"]
with_items:
- "{{ device_name.msg }}"
loop_control:
index_var: item
tags:
- upload
vars:
ansible_command_timeout: 1400
ansible_host: "{{ device_name.msg[item].Name }}"
At the moment, the condition does not work and the software is always downloaded.
Thanks in advance,
Regards,
Jerems
Solved! Go to Solution.
05-23-2023 12:10 AM
More than a cake it is a Roblochon i would like to offer you when you come and visit me in Annecy, FR
Just let me know when you come over
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide