Ansible编写的网络解析器可以正确处理show命令输出。他们创建的其中一些文件位于
https://github.com/network-automation/ansible-network-parsers
我正在寻找命令和输出的网络解析器,如下所示。如果你有擅长这些的人可以帮助你,请告诉我。我们需要上面GitHub命令中编写的端口列表的输出。谢谢你的帮助。我试过几样东西。得到了很多yaml错误。
sffc07ssw01# show port-channel summary
Flags: D - Down P - Up in port-channel (members)
I - Individual H - Hot-standby (LACP only)
s - Suspended r - Module-removed
S - Switched R - Routed
U - Up (port-channel)
M - Not in use. Min-links not met
--------------------------------------------------------------------------------
Group Port- Type Protocol Member Ports
Channel
--------------------------------------------------------------------------------
10 Po10(SD) Eth NONE --
11 Po11(SU) Eth LACP Eth1/1(P) Eth1/2(P)
12 Po12(SU) Eth LACP Eth1/3(P) Eth1/4(P)
100 Po100(SD) Eth NONE --
121 Po121(SD) Eth NONE --
122 Po122(SD) Eth NONE --
123 Po123(SD) Eth NONE --
125 Po125(SD) Eth NONE --发布于 2019-06-26 02:05:12
好的,我们不需要为此编写网络解析器。有人可以解释一下网络解析器是如何工作的,我很想学习。
对于nxos,当我们使用transport作为cli时,我们会收到上面的输出。但是如果我们使用transport作为network_cli,那么输出将已经是字典格式。
ok: [xyz.com] => {
"pc_output": {
"changed": false,
"failed": false,
"stdout": [
{
"TABLE_channel": {
"ROW_channel": [
{
"group": 10,
"layer": "S",
"port-channel": "port-channel10",
"prtcl": "NONE",
"status": "D",
"type": "Eth"
},
{
"TABLE_member": {
"ROW_member": [
{
"port": "Ethernet1/1",
"port-status": "P"
},
{
"port": "Ethernet1/2",
"port-status": "P"
This is the way I processed it
```yml项目看起来像这样
interface_port_channel:
{接口:以太网2/1,channel_group: 122,模式:活动}{接口:以太网2/2,channel_group: 122,模式:活动}
名称: Interface portchannel info
调试: msg="args {{item}}“
名称:使用给定接口配置lacp中继
nxos_config:
线条:
- conf t
-接口{{item.interface}}
-通道组{{item.channel_group}}模式{{item.mode}}
-退出
提供者:"{{ nxos_provider}}“
名称:“获取端口通道摘要”
nxos_command: commands=“显示端口通道摘要”provider="{{nxos_provider_network_cli}}“
寄存器: pc_output
名称:“打印端口通道输出”
调试: var=pc_output
set_fact: channel_group_info="{{run_pc}}“
"{{pc_output.stdout.TABLE_channel.ROW_channel}}“:with_items
时间: item.channel_group == run_pc.group
loop_control:
loop_var: run_pc
调试: var=channel_group_info
断言:
那就是:
-定义了channel_group_info
- channel_group_info.layer == 'S‘
- channel_group_info.status == 'U‘
- channel_group_info.prtcl == "LACP“
success_msg:“端口已切换”
fail_msg:“请检查上面的channel_group_info,确保状态、协议和类型正确”
项目:ports_info=“{{set_fact}}”
"{{channel_group_info.TABLE_member.ROW_member}}“:with_items
when: item.port == ''.join(item.interface.split())
debug: var=ports_info“端口状态”
断言:
那就是:
-定义了ports_info
-ports_info“== -status”端口'P‘
https://stackoverflow.com/questions/56710505
复制相似问题