Upgrading 2960x

I’m sure I’m missing something very simple but have been working on this for a few days. I’m really new to Ansible and would really appreciate any help.

I have AWX
Ansible

My Playbook

Hi

Although this list isn’t for AWX, it’s easy to spot the error because it literally says at the end what is wrong.
The commands parameter expects a list.
See the last example on
https://docs.ansible.com/ansible/latest/modules/ios_command_module.html#examples

hi,

i started to write a universal ios upgrade playbook. The meta playbook includes the playbooks for the specific model upgrades. Sorry for the lengthy post. But when I find some time I will write a better blog article.

Please feel free to ask me again if you have a question regarding this playbooks.

First we have an inventory like:

all:
  hosts: 

    switch01: 
      ansible_host: 192.168.100.149    # DHCP address in staging net

  children:        # grouping in ansible is called „children“
    c9200l:        # grouping according to hardware 
      hosts: 
        switch01: 
      vars: 
        compliant_ios_version: 16.12.01 
        ios_hash: 727cfc785bc304b985656dee660b0382 
        ios_file: cat9k_lite_iosxe.16.12.01.SPA.bin

The meta playbook is like:
---
- hosts: cisco
  vars:
    model: "{{ ansible_net_model | regex_replace('^WS-C(\d+.).*$', '\1') }}"
  tasks:
    - name: Output
      debug:
        msg: "Found model: {{ model }}. Will try to upgrade."
    - name: Include model series specific upgrade
      block:
        - name: do include
          include: "ios-upgrade-{{ model }}.yaml"
      when: (ansible_net_version != compliant_ios_version)

The playbook for a c2960L is:
  - name: Copy IOS to device
    ios_command:
      commands:
        - command: 'copy tftp://[192.168.100.16/{{](http://192.168.100.16/{{) ios_file }} flash:'
          prompt: 'Destination filename \[{{ ios_file }}\]?'
          answer: "\r"
    vars:
      ansible_command_timeout: 600

  - name: Check md5sum of IOS on device
    ios_command:
      commands:
        - command: 'verify /md5 flash:{{ ios_file }} {{ ios_hash }}'
    register: md5_output

  - name: Continue if hash matches
    block:

      - name: Set new boot variable
        ios_config:
          lines: boot system flash:{{ ios_file }}
          save_when: always

      - name: Reboot device
        ios_command:
          commands:
            - command: reload
              prompt: '\[confirm\]'
              answer: "\r"

      - name: Wait for switch to reboot
        wait_for:
          host: "{{ ansible_host }}"
          port: 22
          delay: 60
          timeout: 600
        delegate_to: localhost

      - name: Gather facts of the switch again
        ios_facts:

      - name: Assert that the running IOS version is correct
        assert:
          that:
            - compliant_ios_version == ansible_net_version
          msg: "IOS version does not match compliant version. Upgrade unsuccessful."

    when: '"Verified" in md5_output.stdout[0]'

	

 

Hi

What is the purpose of this message? It seems to bear no question, and does not have any relation to the original message(s)?

I believe Mr. Meier was just sharing an example of a working version of a playbook that does what kanor is trying to do.

It also illustrates your point about the ios_commands module wanting a list.

I found it pretty relevant and am glad he took the time to share that.

I really appreciate everyone’s input to my question.
Thanks

(attachments)