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-22-2023 03:03 AM
Hi @bigevilbeard,
I finally found the correct set_fact parameter :
## Get fact for the current IOSXE version with PyATS
- name: Get fact for the current IOSXE version with PyATS
tags: pre-check, check-version, post-check, install
set_fact:
current_xe_ver: "{{ show_version.results[item]['stdout'][0] | pyats_parser('show version', 'iosxe') }}"
with_items:
- "{{ show_version.results }}"
loop_control:
index_var: item
which is :
current_xe_ver: "{{ show_version.results[item]['stdout'][0] | pyats_parser('show version', 'iosxe') }}"
Thanks to this article :
https://careerkarma.com/blog/python-attributeerror-list-object-has-no-attribute-split/
We use the [0] indexing syntax to access the first item in a record. This corresponds to the name of a cake.
and the initial code :
from github repository :
Thanks again for your time Stuart !
05-13-2023 06:04 AM
Checkout Muhammads Playbook he's doing the same thing (and some more):
HTH
05-15-2023 09:08 AM
Hi @All
I gave it a try but i can not figure out why i have such issues
First here is the code :
## Get IOSXE version with PyATS and compare it with the targer version
- name: Get current IOSXE version
tags: pre-check, check-version, post-check, install
ios_command:
commands:
- show version
register: show_version
with_items:
- "{{ device_name.msg }}"
loop_control:
index_var: item
vars:
ansible_host: "{{ device_name.msg[item].Name }}"
## Get fact for the current IOSXE version with PyATS
- name: Get fact for the current IOSXE version with PyATS
tags: pre-check, check-version, post-check, install
set_fact:
current_xe_ver: "{{ show_version['stdout'][item] | pyats_parser('show version', 'iosxe') }}"
with_items:
- "{{ show_version }}"
loop_control:
index_var: item
And the output:
TASK [Get current IOSXE version] ************************************************************************************************************************************************************************
task path: /Users/jeremierouzet/jeysible/playbooks/Dynamic_inventory/cisco/pb_coll_cisco_device_perform_ios_upgrade.yml:81
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
redirecting (type: modules) ansible.builtin.ios_command to cisco.ios.ios_command
redirecting (type: action) ansible.builtin.ios to cisco.ios.ios
redirecting (type: action) ansible.builtin.ios to cisco.ios.ios
redirecting (type: modules) ansible.builtin.ios_command to cisco.ios.ios_command
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
ok: [netbox] => (item=0) => {
"ansible_index_var": "item",
"ansible_loop_var": "item",
"changed": false,
"invocation": {
"module_args": {
"commands": [
"show version"
],
"interval": 1,
"match": "all",
"provider": null,
"retries": 10,
"wait_for": null
}
},
"item": 0,
"stdout": [
"Cisco IOS XE Software, Version 16.12.04\nCisco IOS Software [Gibraltar], ISR Software (ARMV8EL_LINUX_IOSD-UNIVERSALK9-M), Version 16.12.4, RELEASE SOFTWARE (fc5)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2020 by Cisco Systems, Inc.\nCompiled Thu 09-Jul-20 20:16 by mcpre\n\n\nCisco IOS-XE software, Copyright (c) 2005-2020 by cisco Systems, Inc.\nAll rights reserved. Certain components of Cisco IOS-XE software are\nlicensed under the GNU General Public License (\"GPL\") Version 2.0. \nConfiguration register is 0x2102"
],
"stdout_lines": [
[
"Cisco IOS XE Software, Version 16.12.04",
"Cisco IOS Software [Gibraltar], ISR Software (ARMV8EL_LINUX_IOSD-UNIVERSALK9-M), Version 16.12.4, RELEASE SOFTWARE (fc5)",
"Technical Support: http://www.cisco.com/techsupport",
"Copyright (c) 1986-2020 by Cisco Systems, Inc.",
"Compiled Thu 09-Jul-20 20:16 by mcpre",
"",
"",
"Cisco IOS-XE software, Copyright (c) 2005-2020 by cisco Systems, Inc.",
"All rights reserved. Certain components of Cisco IOS-XE software are",
"licensed under the GNU General Public License (\"GPL\") Version 2.0. The",
"software code licensed under GPL Version 2.0 is free software that comes",
"with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such",
"GPL code under the terms of GPL Version 2.0. For more details, see the",
"documentation or \"License Notice\" file accompanying the IOS-XE software,",
"or the applicable URL provided on the flyer accompanying the IOS-XE",
"software.",
"",
"",
"ROM: 16.12(2r)",
"",
"Jeycisco01 uptime is 21 weeks, 3 days, 8 hours, 30 minutes",
"Uptime for this control processor is 21 weeks, 3 days, 8 hours, 31 minutes",
"System returned to ROM by PowerOn at 10:19:39 CEST Sat Apr 24 2021",
"System restarted at 08:24:53 CET Fri Dec 16 2022",
"System image file is \"bootflash:c1100-universalk9.16.12.04.SPA.bin\"",
"Last reload reason: PowerOn",
"",
"",
"",
"States and local country laws governing import, export, transfer and",
"use. Delivery of Cisco cryptographic products does not imply",
"third-party authority to import, export, distribute or use encryption.",
"Importers, exporters, distributors and users are responsible for",
"compliance with U.S. and local country laws. By using this product you",
"agree to comply with applicable laws and regulations. If you are unable",
"to comply with U.S. and local laws, return this product immediately.",
"",
"If you require further assistance please contact us by sending email to",
"export@cisco.com.",
"",
"",
"",
"Suite License Information for Module:'esg' ",
"",
"--------------------------------------------------------------------------------",
"Suite Suite Current Type Suite Next reboot ",
"--------------------------------------------------------------------------------",
"FoundationSuiteK9 None Smart License None ",
"securityk9",
"appxk9",
"",
"",
"Technology Package License Information: ",
"",
"-----------------------------------------------------------------",
"Technology Technology-package Technology-package",
" Current Type Next reboot ",
"------------------------------------------------------------------",
"appxk9 appxk9 Smart License appxk9",
"uck9 None Smart License None",
"securityk9 None Smart License None",
"ipbase ipbasek9 Smart License ipbasek9",
"",
"The current throughput level is unthrottled ",
"",
"",
"Smart Licensing Status: REGISTERED/OUT OF COMPLIANCE",
"",
"cisco C1111-8P (1RU) processor with 1398091K/6147K bytes of memory.",
"Processor board ID FCZ2247E1CX",
"3 Virtual Ethernet interfaces",
"10 Gigabit Ethernet interfaces",
"32768K bytes of non-volatile configuration memory.",
"4194304K bytes of physical memory.",
"2863103K bytes of flash memory at bootflash:.",
"0K bytes of WebUI ODM Files at webui:.",
"",
"Configuration register is 0x2102"
]
]
}
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
redirecting (type: modules) ansible.builtin.ios_command to cisco.ios.ios_command
redirecting (type: action) ansible.builtin.ios to cisco.ios.ios
redirecting (type: action) ansible.builtin.ios to cisco.ios.ios
redirecting (type: modules) ansible.builtin.ios_command to cisco.ios.ios_command
ok: [netbox] => (item=1) => {
"ansible_index_var": "item",
"ansible_loop_var": "item",
"changed": false,
"invocation": {
"module_args": {
"commands": [
"show version"
],
"interval": 1,
"match": "all",
"provider": null,
"retries": 10,
"wait_for": null
}
},
"item": 1,
"stdout": [
"Cisco IOS XE Software, Version 16.12.04\nCisco IOS Software [Gibraltar], ISR Software (ARMV8EL_LINUX_IOSD-UNIVERSALK9-M), Version 16.12.4, RELEASE SOFTWARE (fc5)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2020 by Cisco Systems, Inc.\nCompiled Thu 09-Jul-20 20:16 by mcpre\n\n\nCisco IOS-XE software, Copyright (c) 2005-2020 by cisco Systems, Inc.\nAll rights reserved. Certain components of Cisco IOS-XE software are\nlicensed under the GNU General Public License (\"GPL\") Version 2.0. \nConfiguration register is 0x2102"
],
"stdout_lines": [
[
"Cisco IOS XE Software, Version 16.12.04",
"Cisco IOS Software [Gibraltar], ISR Software (ARMV8EL_LINUX_IOSD-UNIVERSALK9-M), Version 16.12.4, RELEASE SOFTWARE (fc5)",
"Technical Support: http://www.cisco.com/techsupport",
"Copyright (c) 1986-2020 by Cisco Systems, Inc.",
"Compiled Thu 09-Jul-20 20:16 by mcpre",
"",
"",
"Cisco IOS-XE software, Copyright (c) 2005-2020 by cisco Systems, Inc.",
"All rights reserved. Certain components of Cisco IOS-XE software are",
"licensed under the GNU General Public License (\"GPL\") Version 2.0. The",
"software code licensed under GPL Version 2.0 is free software that comes",
"with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such",
"GPL code under the terms of GPL Version 2.0. For more details, see the",
"documentation or \"License Notice\" file accompanying the IOS-XE software,",
"or the applicable URL provided on the flyer accompanying the IOS-XE",
"software.",
"",
"",
"ROM: 16.12(2r)",
"",
"Jeycisco02 uptime is 21 weeks, 3 days, 8 hours, 30 minutes",
"Uptime for this control processor is 21 weeks, 3 days, 8 hours, 31 minutes",
"System returned to ROM by PowerOn at 18:42:31 CEST Mon Oct 12 2020",
"System restarted at 08:24:50 CET Fri Dec 16 2022",
"System image file is \"bootflash:c1100-universalk9.16.12.04.SPA.bin\"",
"Last reload reason: PowerOn",
"",
"",
"",
"States and local country laws governing import, export, transfer and",
"use. Delivery of Cisco cryptographic products does not imply",
"third-party authority to import, export, distribute or use encryption.",
"Importers, exporters, distributors and users are responsible for",
"compliance with U.S. and local country laws. By using this product you",
"agree to comply with applicable laws and regulations. If you are unable",
"to comply with U.S. and local laws, return this product immediately.",
"",
"A summary of U.S. laws governing Cisco cryptographic products may be found at:",
"",
"If you require further assistance please contact us by sending email to",
"export@cisco.com.",
"",
"",
"",
"Suite License Information for Module:'esg' ",
"",
"--------------------------------------------------------------------------------",
"Suite Suite Current Type Suite Next reboot ",
"--------------------------------------------------------------------------------",
"FoundationSuiteK9 None Smart License None ",
"securityk9",
"appxk9",
"",
"",
"Technology Package License Information: ",
"",
"-----------------------------------------------------------------",
"Technology Technology-package Technology-package",
" Current Type Next reboot ",
"------------------------------------------------------------------",
"appxk9 appxk9 Smart License appxk9",
"uck9 None Smart License None",
"securityk9 None Smart License None",
"ipbase ipbasek9 Smart License ipbasek9",
"",
"The current throughput level is unthrottled ",
"",
"",
"Smart Licensing Status: REGISTERED/OUT OF COMPLIANCE",
"",
"cisco C1111-8P (1RU) processor with 1398091K/6147K bytes of memory.",
"Processor board ID FCZ2421C30S",
"1 Virtual Ethernet interface",
"10 Gigabit Ethernet interfaces",
"32768K bytes of non-volatile configuration memory.",
"4194304K bytes of physical memory.",
"2863103K bytes of flash memory at bootflash:.",
"0K bytes of WebUI ODM Files at webui:.",
"",
"Configuration register is 0x2102"
]
]
}
TASK [Get fact for the current IOSXE version with PyATS] ************************************************************************************************************************************************
task path: /Users/jeremierouzet/jeysible/playbooks/Dynamic_inventory/cisco/pb_coll_cisco_device_perform_ios_upgrade.yml:96
fatal: [netbox]: FAILED! => {
"msg": "Unable to parse output for command 'show version' ('dict object' has no attribute 'stdout')"
}
PLAY RECAP **********************************************************************************************************************************************************************************************
netbox : ok=6 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Thanks in advance for your kind help.
Regards,
Jerems
05-16-2023 02:55 AM
@Jerems trying swapping this line
current_xe_ver: "{{ show_version['stdout'][item] | pyats_parser('show version', 'iosxe') }}
current_xe_ver: "{{ show_version['stdout_lines'][item] | pyats_parser('show version', 'iosxe') }}"
05-16-2023 05:54 AM
Hi @bigevilbeard ,
Thank you for your contribution.
Here is the modified code:
## Get fact for the current IOSXE version with PyATS
- name: Get fact for the current IOSXE version with PyATS
tags: pre-check, check-version, post-check, install
set_fact:
current_xe_ver: "{{ show_version['stdout_lines'][item] | pyats_parser('show version', 'iosxe') }}"
with_items:
- "{{ show_version }}"
loop_control:
index_var: item
And here is the output :
TASK [Get fact for the current IOSXE version with PyATS] ************************************************************************************************************************************************************************
task path: /Users/jeremierouzet/jeysible/playbooks/Dynamic_inventory/cisco/pb_coll_cisco_device_perform_ios_upgrade.yml:96
fatal: [netbox]: FAILED! => {
"msg": "Unable to parse output for command 'show version' ('dict object' has no attribute 'stdout_lines')"
}
PLAY RECAP **********************************************************************************************************************************************************************************************************************
netbox : ok=6 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Thanks again for your kind help,
Jerems
05-16-2023 06:15 AM
Try this buddy as it looked like from the error, because the pyats_parser filter is expecting the output of the show version command to be in a list format (i think - lol!)
- name: Get fact for the current IOSXE version with PyATS
tags: pre-check, check-version, post-check, install
set_fact:
current_xe_ver: "{{ show_version['stdout'] | to_list | pyats_parser('show version', 'iosxe') }}"
with_items:
- "{{ show_version }}"
loop_control:
index_var: item
05-16-2023 06:49 AM
Hi,
The playbook :
# Get fact for the current IOSXE version with PyATS
- name: Get fact for the current IOSXE version with PyATS
tags: pre-check, check-version, post-check, install
set_fact:
current_xe_ver: "{{ show_version['stdout'] | to_list | pyats_parser('show version', 'iosxe') }}"
with_items:
- "{{ show_version }}"
loop_control:
index_var: item
The output:
TASK [Get fact for the current IOSXE version with PyATS] ************************************************************************************************************************************************************************
task path: /Users/jeremierouzet/jeysible/playbooks/Dynamic_inventory/cisco/pb_coll_cisco_device_perform_ios_upgrade.yml:96
fatal: [netbox]: FAILED! => {
"msg": "template error while templating string: No filter named 'to_list'.. String: {{ show_version['stdout'] | to_list | pyats_parser('show version', 'iosxe') }}"
}
PLAY RECAP **********************************************************************************************************************************************************************************************************************
netbox
Thanks and Regards,
05-16-2023 06:58 AM
@Jerems do you have Jinja2 installed?
05-16-2023 07:05 AM - edited 05-16-2023 07:35 AM
Yes i do use Jinja2 to template my Cisco & Junos in my Ansible instance
05-16-2023 07:28 AM
I am wondering if that last error is due to that not being found/installed as i think to_list filter is a Jinja2 filter, i recall its not available by default in Ansible.
05-16-2023 07:38 AM - edited 05-16-2023 07:40 AM
And to be honest, i have a lack of ansible knowledge...I always loose myself in such output errors, wondering where i did it bad
Let me have a deeper look at it tonight. Your contribution encourages me to push further the investigations.
Thanks again.
05-16-2023 11:38 AM - edited 05-16-2023 11:40 AM
This one doesn't work either
## Get IOSXE version with PyATS and compare it with the targer version
- name: Get current IOSXE version
tags: pre-check, check-version, post-check, install
ios_command:
commands:
- show version
register: show_version
with_items:
- "{{ device_name.msg }}"
loop_control:
index_var: item
vars:
ansible_host: "{{ device_name.msg[item].Name }}"
# Debug previous command registered values
- name: Debug previous command registered values
ansible.builtin.debug:
var: show_version
## Get fact for the current IOSXE version with PyATS
- name: Get fact for the current IOSXE version with PyATS
tags: pre-check, check-version, post-check, install
set_fact:
current_xe_ver: "{{ show_version.results[item].stdout | list | pyats_parser('show version', 'iosxe') }}"
with_items:
- "{{ show_version.results }}"
loop_control:
index_var: item
And the output :
TASK [Debug previous command registered values] *********************************************************************************************************************************************************
task path: /Users/jeremierouzet/jeysible/playbooks/Dynamic_inventory/cisco/pb_coll_cisco_device_perform_ios_upgrade.yml:96
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
ok: [netbox] => {
"show_version": {
"changed": false,
"msg": "All items completed",
"results": [
{
"ansible_index_var": "item",
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"commands": [
"show version"
],
"interval": 1,
"match": "all",
"provider": null,
"retries": 10,
"wait_for": null
}
},
"item": 0,
"stdout": [
"Cisco IOS XE Software, Version 16.12.04\nCisco IOS Software [Gibraltar], ISR Software (ARMV8EL_LINUX_IOSD-UNIVERSALK9-M), Version 16.12.4, RELEASE SOFTWARE (fc5)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2020 by Cisco Systems, Inc.\nCompiled Thu 09-Jul-20 20:16 by mcpre\n\n\nCisco IOS-XE software, Copyright (c) 2005-2020 by cisco Systems, Inc.\nAll rights reserved. Certain components of Cisco IOS-XE software are\nlicensed under the GNU General Public License (\"GPL\") Version 2.0. The\nsoftware code licensed under GPL Version 2.0 is free software that comes\nwith ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such\nGPL code under the terms of GPL Version 2.0. For more details, see the\ndocumentation or \"License Notice\" file accompanying the IOS-XE software,\nor the applicable URL provided on the flyer accompanying the IOS-XE\nsoftware.\n\n\nROM: 16.12(2r)\n\nJeycisco01 uptime is 21 weeks, 4 days, 11 hours, 11 minutes\nUptime for this control processor is 21 weeks, 4 days, 11 hours, 12 minutes\nSystem returned to ROM by PowerOn at 10:19:39 CEST Sat Apr 24 2021\nSystem restarted at 08:24:53 CET Fri Dec 16 2022\nSystem image file is \"bootflash:c1100-universalk9.16.12.04.SPA.bin\"\nLast reload reason: PowerOn\n\n\n\nThis product contains cryptographic features and is subject to United\nStates and local country laws governing import, export, transfer and\nuse. Delivery of Cisco cryptographic products does not imply\nthird-party authority to import, export, distribute or use encryption.\nImporters, exporters, distributors and users are responsible for\ncompliance with U.S. and local country laws. By using this product you\nagree to comply with applicable laws and regulations. If you are unable\nto comply with U.S. and local laws, return this product immediately.\n\nA summary of U.S. laws governing Cisco cryptographic products may be found at:\nhttp://www.cisco.com/wwl/export/crypto/tool/stqrg.html\n\nIf you require further assistance please contact us by sending email to\nexport@cisco.com.\n\n\n\nSuite License Information for Module:'esg' \n\n--------------------------------------------------------------------------------\nSuite Suite Current Type Suite Next reboot \n--------------------------------------------------------------------------------\nFoundationSuiteK9 None Smart License None \nsecurityk9\nappxk9\n\n\nTechnology Package License Information: \n\n-----------------------------------------------------------------\nTechnology Technology-package Technology-package\n Current Type Next reboot \n------------------------------------------------------------------\nappxk9 appxk9 Smart License appxk9\nuck9 None Smart License None\nsecurityk9 None Smart License None\nipbase ipbasek9 Smart License ipbasek9\n\nThe current throughput level is unthrottled \n\n\nSmart Licensing Status: REGISTERED/OUT OF COMPLIANCE\n\ncisco C1111-8P (1RU) processor with 1398091K/6147K bytes of memory.\nProcessor board ID FCZ2247E1CX\n3 Virtual Ethernet interfaces\n10 Gigabit Ethernet interfaces\n32768K bytes of non-volatile configuration memory.\n4194304K bytes of physical memory.\n2863103K bytes of flash memory at bootflash:.\n0K bytes of WebUI ODM Files at webui:.\n\nConfiguration register is 0x2102"
],
"stdout_lines": [
[
"Cisco IOS XE Software, Version 16.12.04",
"Cisco IOS Software [Gibraltar], ISR Software (ARMV8EL_LINUX_IOSD-UNIVERSALK9-M), Version 16.12.4, RELEASE SOFTWARE (fc5)",
"Technical Support: http://www.cisco.com/techsupport",
"Copyright (c) 1986-2020 by Cisco Systems, Inc.",
"Compiled Thu 09-Jul-20 20:16 by mcpre",
"",
"",
"Cisco IOS-XE software, Copyright (c) 2005-2020 by cisco Systems, Inc.",
"All rights reserved. Certain components of Cisco IOS-XE software are",
"licensed under the GNU General Public License (\"GPL\") Version 2.0. The",
"software code licensed under GPL Version 2.0 is free software that comes",
"with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such",
"GPL code under the terms of GPL Version 2.0. For more details, see the",
"documentation or \"License Notice\" file accompanying the IOS-XE software,",
"or the applicable URL provided on the flyer accompanying the IOS-XE",
"software.",
"",
"",
"ROM: 16.12(2r)",
"",
"Jeycisco01 uptime is 21 weeks, 4 days, 11 hours, 11 minutes",
"Uptime for this control processor is 21 weeks, 4 days, 11 hours, 12 minutes",
"System returned to ROM by PowerOn at 10:19:39 CEST Sat Apr 24 2021",
"System restarted at 08:24:53 CET Fri Dec 16 2022",
"System image file is \"bootflash:c1100-universalk9.16.12.04.SPA.bin\"",
"Last reload reason: PowerOn",
"",
"",
"",
"This product contains cryptographic features and is subject to United",
"States and local country laws governing import, export, transfer and",
"use. Delivery of Cisco cryptographic products does not imply",
"third-party authority to import, export, distribute or use encryption.",
"Importers, exporters, distributors and users are responsible for",
"compliance with U.S. and local country laws. By using this product you",
"agree to comply with applicable laws and regulations. If you are unable",
"to comply with U.S. and local laws, return this product immediately.",
"",
"A summary of U.S. laws governing Cisco cryptographic products may be found at:",
"http://www.cisco.com/wwl/export/crypto/tool/stqrg.html",
"",
"If you require further assistance please contact us by sending email to",
"export@cisco.com.",
"",
"",
"",
"Suite License Information for Module:'esg' ",
"",
"--------------------------------------------------------------------------------",
"Suite Suite Current Type Suite Next reboot ",
"--------------------------------------------------------------------------------",
"FoundationSuiteK9 None Smart License None ",
"securityk9",
"appxk9",
"",
"",
"Technology Package License Information: ",
"",
"-----------------------------------------------------------------",
"Technology Technology-package Technology-package",
" Current Type Next reboot ",
"------------------------------------------------------------------",
"appxk9 appxk9 Smart License appxk9",
"uck9 None Smart License None",
"securityk9 None Smart License None",
"ipbase ipbasek9 Smart License ipbasek9",
"",
"The current throughput level is unthrottled ",
"",
"",
"Smart Licensing Status: REGISTERED/OUT OF COMPLIANCE",
"",
"cisco C1111-8P (1RU) processor with 1398091K/6147K bytes of memory.",
"Processor board ID FCZ2247E1CX",
"3 Virtual Ethernet interfaces",
"10 Gigabit Ethernet interfaces",
"32768K bytes of non-volatile configuration memory.",
"4194304K bytes of physical memory.",
"2863103K bytes of flash memory at bootflash:.",
"0K bytes of WebUI ODM Files at webui:.",
"",
"Configuration register is 0x2102"
]
]
},
{
"ansible_index_var": "item",
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"commands": [
"show version"
],
"interval": 1,
"match": "all",
"provider": null,
"retries": 10,
"wait_for": null
}
},
"item": 1,
"stdout": [
"Cisco IOS XE Software, Version 16.12.04\nCisco IOS Software [Gibraltar], ISR Software (ARMV8EL_LINUX_IOSD-UNIVERSALK9-M), Version 16.12.4, RELEASE SOFTWARE (fc5)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2020 by Cisco Systems, Inc.\nCompiled Thu 09-Jul-20 20:16 by mcpre\n\n\nCisco IOS-XE software, Copyright (c) 2005-2020 by cisco Systems, Inc.\nAll rights reserved. Certain components of Cisco IOS-XE software are\nlicensed under the GNU General Public License (\"GPL\") Version 2.0. The\nsoftware code licensed under GPL Version 2.0 is free software that comes\nwith ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such\nGPL code under the terms of GPL Version 2.0. For more details, see the\ndocumentation or \"License Notice\" file accompanying the IOS-XE software,\nor the applicable URL provided on the flyer accompanying the IOS-XE\nsoftware.\n\n\nROM: 16.12(2r)\n\nJeycisco02 uptime is 21 weeks, 4 days, 11 hours, 11 minutes\nUptime for this control processor is 21 weeks, 4 days, 11 hours, 12 minutes\nSystem returned to ROM by PowerOn at 18:42:31 CEST Mon Oct 12 2020\nSystem restarted at 08:24:50 CET Fri Dec 16 2022\nSystem image file is \"bootflash:c1100-universalk9.16.12.04.SPA.bin\"\nLast reload reason: PowerOn\n\n\n\nThis product contains cryptographic features and is subject to United\nStates and local country laws governing import, export, transfer and\nuse. Delivery of Cisco cryptographic products does not imply\nthird-party authority to import, export, distribute or use encryption.\nImporters, exporters, distributors and users are responsible for\ncompliance with U.S. and local country laws. By using this product you\nagree to comply with applicable laws and regulations. If you are unable\nto comply with U.S. and local laws, return this product immediately.\n\nA summary of U.S. laws governing Cisco cryptographic products may be found at:\nhttp://www.cisco.com/wwl/export/crypto/tool/stqrg.html\n\nIf you require further assistance please contact us by sending email to\nexport@cisco.com.\n\n\n\nSuite License Information for Module:'esg' \n\n--------------------------------------------------------------------------------\nSuite Suite Current Type Suite Next reboot \n--------------------------------------------------------------------------------\nFoundationSuiteK9 None Smart License None \nsecurityk9\nappxk9\n\n\nTechnology Package License Information: \n\n-----------------------------------------------------------------\nTechnology Technology-package Technology-package\n Current Type Next reboot \n------------------------------------------------------------------\nappxk9 appxk9 Smart License appxk9\nuck9 None Smart License None\nsecurityk9 None Smart License None\nipbase ipbasek9 Smart License ipbasek9\n\nThe current throughput level is unthrottled \n\n\nSmart Licensing Status: REGISTERED/OUT OF COMPLIANCE\n\ncisco C1111-8P (1RU) processor with 1398091K/6147K bytes of memory.\nProcessor board ID FCZ2421C30S\n1 Virtual Ethernet interface\n10 Gigabit Ethernet interfaces\n32768K bytes of non-volatile configuration memory.\n4194304K bytes of physical memory.\n2863103K bytes of flash memory at bootflash:.\n0K bytes of WebUI ODM Files at webui:.\n\nConfiguration register is 0x2102"
],
"stdout_lines": [
[
"Cisco IOS XE Software, Version 16.12.04",
"Cisco IOS Software [Gibraltar], ISR Software (ARMV8EL_LINUX_IOSD-UNIVERSALK9-M), Version 16.12.4, RELEASE SOFTWARE (fc5)",
"Technical Support: http://www.cisco.com/techsupport",
"Copyright (c) 1986-2020 by Cisco Systems, Inc.",
"Compiled Thu 09-Jul-20 20:16 by mcpre",
"",
"",
"Cisco IOS-XE software, Copyright (c) 2005-2020 by cisco Systems, Inc.",
"All rights reserved. Certain components of Cisco IOS-XE software are",
"licensed under the GNU General Public License (\"GPL\") Version 2.0. The",
"software code licensed under GPL Version 2.0 is free software that comes",
"with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such",
"GPL code under the terms of GPL Version 2.0. For more details, see the",
"documentation or \"License Notice\" file accompanying the IOS-XE software,",
"or the applicable URL provided on the flyer accompanying the IOS-XE",
"software.",
"",
"",
"ROM: 16.12(2r)",
"",
"Jeycisco02 uptime is 21 weeks, 4 days, 11 hours, 11 minutes",
"Uptime for this control processor is 21 weeks, 4 days, 11 hours, 12 minutes",
"System returned to ROM by PowerOn at 18:42:31 CEST Mon Oct 12 2020",
"System restarted at 08:24:50 CET Fri Dec 16 2022",
"System image file is \"bootflash:c1100-universalk9.16.12.04.SPA.bin\"",
"Last reload reason: PowerOn",
"",
"",
"",
"This product contains cryptographic features and is subject to United",
"States and local country laws governing import, export, transfer and",
"use. Delivery of Cisco cryptographic products does not imply",
"third-party authority to import, export, distribute or use encryption.",
"Importers, exporters, distributors and users are responsible for",
"compliance with U.S. and local country laws. By using this product you",
"agree to comply with applicable laws and regulations. If you are unable",
"to comply with U.S. and local laws, return this product immediately.",
"",
"A summary of U.S. laws governing Cisco cryptographic products may be found at:",
"http://www.cisco.com/wwl/export/crypto/tool/stqrg.html",
"",
"If you require further assistance please contact us by sending email to",
"export@cisco.com.",
"",
"",
"",
"Suite License Information for Module:'esg' ",
"",
"--------------------------------------------------------------------------------",
"Suite Suite Current Type Suite Next reboot ",
"--------------------------------------------------------------------------------",
"FoundationSuiteK9 None Smart License None ",
"securityk9",
"appxk9",
"",
"",
"Technology Package License Information: ",
"",
"-----------------------------------------------------------------",
"Technology Technology-package Technology-package",
" Current Type Next reboot ",
"------------------------------------------------------------------",
"appxk9 appxk9 Smart License appxk9",
"uck9 None Smart License None",
"securityk9 None Smart License None",
"ipbase ipbasek9 Smart License ipbasek9",
"",
"The current throughput level is unthrottled ",
"",
"",
"Smart Licensing Status: REGISTERED/OUT OF COMPLIANCE",
"",
"cisco C1111-8P (1RU) processor with 1398091K/6147K bytes of memory.",
"Processor board ID FCZ2421C30S",
"1 Virtual Ethernet interface",
"10 Gigabit Ethernet interfaces",
"32768K bytes of non-volatile configuration memory.",
"4194304K bytes of physical memory.",
"2863103K bytes of flash memory at bootflash:.",
"0K bytes of WebUI ODM Files at webui:.",
"",
"Configuration register is 0x2102"
]
]
}
],
"skipped": false
}
}
TASK [Get fact for the current IOSXE version with PyATS] ************************************************************************************************************************************************
task path: /Users/jeremierouzet/jeysible/playbooks/Dynamic_inventory/cisco/pb_coll_cisco_device_perform_ios_upgrade.yml:101
fatal: [netbox]: FAILED! => {
"msg": "Unable to parse output for command 'show version' ('list' object has no attribute 'splitlines')"
}
I googled this one but didn't find any relevant clues:
"msg": "Unable to parse output for command 'show version' ('list' object has no attribute 'splitlines')"
Many thanks in advance for your kind help/advises.
Regards,
Jerems
05-16-2023 11:47 PM
Hmm so the message would imply the pyats_parser filter is trying to access an attribute called splitlines on a list object, but the list object does not have this attribute? Try... (another guess)
- name: Get fact for the current IOSXE version with PyATS
tags:
- pre-check
- check-version
- post-check
- install
set_fact:
current_xe_ver: "{{ show_version['stdout'].splitlines() | pyats_parser('show version', 'iosxe') }}"
with_items:
- "{{ show_version }}"
loop_control:
index_var: item
05-22-2023 03:03 AM
Hi @bigevilbeard,
I finally found the correct set_fact parameter :
## Get fact for the current IOSXE version with PyATS
- name: Get fact for the current IOSXE version with PyATS
tags: pre-check, check-version, post-check, install
set_fact:
current_xe_ver: "{{ show_version.results[item]['stdout'][0] | pyats_parser('show version', 'iosxe') }}"
with_items:
- "{{ show_version.results }}"
loop_control:
index_var: item
which is :
current_xe_ver: "{{ show_version.results[item]['stdout'][0] | pyats_parser('show version', 'iosxe') }}"
Thanks to this article :
https://careerkarma.com/blog/python-attributeerror-list-object-has-no-attribute-split/
We use the [0] indexing syntax to access the first item in a record. This corresponds to the name of a cake.
and the initial code :
from github repository :
Thanks again for your time Stuart !
05-23-2023 12:02 AM
arh... cool - now tell me more about the cake and when i get some!
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