问题描述
我有一个剧本可以从开关中检索“显示版本”输出,并且使用断言我想在输出中匹配一个字符串“NXOS:版本 9.3(6)”。如果成功,则打印成功消息,否则打印失败消息。使用以下脚本,我总是收到失败的消息。
---
-
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"
开关的打印输出如下。由于数据结构很重要,我正在粘贴完整显示的输出
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,\" and unless","otherwise stated,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),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):"
]
]
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)