cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3772
Views
9
Helpful
15
Replies

Ansible Playbook Upgrade IOS-XE with Condition

Jerems
Spotlight
Spotlight

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

15 Replies 15

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