I have a playbook to retrieve show version
output from a Cisco NX-OS switch and using assert
_module.
I want to match a string "NXOS: version 9.3(6)" in the output. If succeeds, then print success message, or else fail message. With the below scripts I am always getting failed message.
---
-
connection: network_cli
gather_facts: false
hosts: LAB_LF
tasks:
-
name: "show commands"
nxos_command:
commands:
- command: show version
register: show_version
ignore_errors: true
-
debug:
msg: "{{ show_version }}"
name: "display the output from switch"
-
assert:
that:
- "'NXOS: version 9.3(6)' in show_version.stdout"
success_msg: "Passed: All Leaf have current OS"
fail_msg: "Failed: wrong os"
ignore_errors: yes
when: inventory_hostname in groups['LAB_LF0304']
name: "assert the output from switch"
Printed output from the switch is below. As the data structure is important, I am pasting full displayed output
TASK [display the output from switch] *******************************************************************************************
ok: [LAB_LF03] => {
"msg": {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"failed": false,
"stdout": [
"Cisco Nexus Operating System (NX-OS) Software\nTAC support: http://www.cisco.com/tac\nCopyright (C) 2002-2020, Cisco and/or its affiliates.\nAll rights reserved.\nThe copyrights to certain works contained in this software are\nowned by other third parties and used and distributed under their own\nlicenses, such as open source. This software is provided \"as is,\" and unless\notherwise stated, there is no warranty, express or implied, including but not\nlimited to warranties of merchantability and fitness for a particular purpose.\nCertain components of this software are licensed under\nthe GNU General Public License (GPL) version 2.0 or \nGNU General Public License (GPL) version 3.0 or the GNU\nLesser General Public License (LGPL) Version 2.1 or \nLesser General Public License (LGPL) Version 2.0. \nA copy of each such license is available at\nhttp://www.opensource.org/licenses/gpl-2.0.php and\nhttp://opensource.org/licenses/gpl-3.0.html and\nhttp://www.opensource.org/licenses/lgpl-2.1.php and\nhttp://www.gnu.org/licenses/old-licenses/library.txt.\n\nSoftware\n BIOS: version 05.42\n NXOS: version 9.3(6)\n BIOS compile time: 06/14/2020\n NXOS image file is: bootflash:///nxos.9.3.6.bin\n NXOS compile time: 11/9/2020 23:00:00 [11/10/2020 20:00:21]\n\n\nHardware\n cisco Nexus9000 C9336C-FX2 Chassis \n Intel(R) Xeon(R) CPU D-1526 @ 1.80GHz with 24569968 kB of memory.\n Processor Board ID FDO2449113F\n\n Device name: LAB-LF03\n bootflash: 115805708 kB\nKernel uptime is 82 day(s), 20 hour(s), 0 minute(s), 44 second(s)\n\nLast reset at 832054 usecs after Thu Apr 15 13:33:53 2021\n Reason: Reset due to upgrade\n System version: 9.2(3)\n Service: \n\nplugin\n Core Plugin, Ethernet Plugin\n\nActive Package(s):"
],
"stdout_lines": [
[
"Cisco Nexus Operating System (NX-OS) Software",
"TAC support: http://www.cisco.com/tac",
"Copyright (C) 2002-2020, Cisco and/or its affiliates.",
"All rights reserved.",
"The copyrights to certain works contained in this software are",
"owned by other third parties and used and distributed under their own",
"licenses, such as open source. This software is provided \"as is,\" and unless",
"otherwise stated, there is no warranty, express or implied, including but not",
"limited to warranties of merchantability and fitness for a particular purpose.",
"Certain components of this software are licensed under",
"the GNU General Public License (GPL) version 2.0 or ",
"GNU General Public License (GPL) version 3.0 or the GNU",
"Lesser General Public License (LGPL) Version 2.1 or ",
"Lesser General Public License (LGPL) Version 2.0. ",
"A copy of each such license is available at",
"http://www.opensource.org/licenses/gpl-2.0.php and",
"http://opensource.org/licenses/gpl-3.0.html and",
"http://www.opensource.org/licenses/lgpl-2.1.php and",
"http://www.gnu.org/licenses/old-licenses/library.txt.",
"",
"Software",
" BIOS: version 05.42",
" NXOS: version 9.3(6)",
" BIOS compile time: 06/14/2020",
" NXOS image file is: bootflash:///nxos.9.3.6.bin",
" NXOS compile time: 11/9/2020 23:00:00 [11/10/2020 20:00:21]",
"",
"",
"Hardware",
" cisco Nexus9000 C9336C-FX2 Chassis ",
" Intel(R) Xeon(R) CPU D-1526 @ 1.80GHz with 24569968 kB of memory.",
" Processor Board ID ",
"",
" Device name: LAB-LF03",
" bootflash: 115805708 kB",
"Kernel uptime is 82 day(s), 20 hour(s), 0 minute(s), 44 second(s)",
"",
"Last reset at 832054 usecs after Thu Apr 15 13:33:53 2021",
" Reason: Reset due to upgrade",
" System version: 9.2(3)",
" Service: ",
"",
"plugin",
" Core Plugin, Ethernet Plugin",
"",
"Active Package(s):"
]
]
}
}