Хорошо, нам не нужно писать сетевой анализатор для этого.Кто-то может объяснить, как работает сетевой синтаксический анализатор, я хотел бы узнать.
Для nxos, когда мы используем транспорт в качестве cli, мы получаем вывод выше.Но если мы будем использовать транспорт как 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
item looks like this
interface_port_channel:
- { interface: Ethernet 2/1, channel_group: 122, mode: active }
- { interface: Ethernet 2/2, channel_group: 122, mode: active }
---
- name: Interface portchannel info
debug: msg="args {{item}} "
- name: configure lacp trunk with the given interfaces
nxos_config:
lines:
- conf t
- interface {{item.interface}}
- channel-group {{item.channel_group}} mode {{item.mode}}
- exit
provider: "{{ nxos_provider}}"
- name: "Get Port-channel summary"
nxos_command: commands="show port-channel summary" provider="{{nxos_provider_network_cli}}"
register: pc_output
- name: "Printing the port channel output"
debug: var=pc_output
- set_fact: channel_group_info="{{run_pc}}"
with_items: "{{pc_output.stdout[0].TABLE_channel.ROW_channel}}"
when: item.channel_group == run_pc.group
loop_control:
loop_var: run_pc
- debug: var=channel_group_info
- assert:
that:
- channel_group_info is defined
- channel_group_info.layer == 'S'
- channel_group_info.status == 'U'
- channel_group_info.prtcl == "LACP"
success_msg: "Port is switched"
fail_msg: "Please check channel_group_info above to make sure Status, protocol and type is correct"
- set_fact: ports_info="{{item}}"
with_items: "{{channel_group_info.TABLE_member.ROW_member}}"
when: item.port == ''.join(item.interface.split())
- debug: var=ports_info["port-status"]
- assert:
that:
- ports_info is defined
- ports_info["port-status"] == 'P'