Ansible cisco ios,改变接口上的vlan
Ansible cisco ios, change vlan on interface
Ansible cisco ios,更改接口上的 vlan
我只是初学者(ansible 2.7.7),还有很多文献要研究,但希望以后能完全学会
现在我正在尝试在剧本中写下以下内容
处于“线路协议已关闭”状态的端口上接收或发送的数据包数为0
运行 端口“switchport access vlan 537”上的命令
我可以在ios_facts中获取端口状态,但是没有关于计数器的信息。你能在剧本上告诉我吗?我该如何实施?
- name: Collect IOS facts
hosts: ciscoswitch
tasks:
- name: Facts
ios_command:
commands: show interfaces counters | i 0 0
register: ios_comm_result
它的观点:
{
"changed": false,
"failed": false,
"stdout": [
"Fa0/6 0 0 0 0 \nFa0/7 0 0 0 0 \nFa0/8 0 0 0 0 \nGi0/2 0 0 0 0 \nFa0/6 0 0 0 0 \nFa0/7 0 0 0 0 \nFa0/8 0 0 0 0 \nGi0/2 0 0 0 0"
],
"stdout_lines": [
[
"Fa0/6 0 0 0 0 ",
"Fa0/7 0 0 0 0 ",
"Fa0/8 0 0 0 0 ",
"Gi0/2 0 0 0 0 ",
"Fa0/6 0 0 0 0 ",
"Fa0/7 0 0 0 0 ",
"Fa0/8 0 0 0 0 ",
"Gi0/2 0 0 0 0"
]
]
}
我如何解析寄存器 ios_comm_result 并发送命令以更改寄存器结果中的端口?
这是一个较旧的 post,所以您可能已经明白了,但这里有一个代码示例:
tasks:
- name: Facts
ios_command:
commands: show interfaces counters | i 0 0
register: ios_comm_result
- name: get a list of ports to modify
set_fact:
newlist: "{{newlist + [item.split()[0]]}}"
with_items: "{{ios_comm_result.stdout_lines}}"
- name: Apply vlan command
ios_config:
lines:
- "sw acc vlan 537"
parents: "int {{ item.0 }}"
loop: "{{newlist|zip(nMatches)|list }}"
Post Tom Klimek - 是正确的,但在语法上有一些小错误
正确:
- name: Collect IOS facts
hosts: Switch
tasks:
- name: Facts
ios_command:
commands: show interfaces counters | i 0 0
register: ios_comm_result
- name: get a list of ports to modify
set_fact:
newlist: "{{(newlist | default([])) + [item.split()[0]]}}"
with_items: "{{ios_comm_result.stdout_lines}}"
- name: Apply vlan command
ios_config:
lines:
- "sw acc vlan 998"
parents: "int {{ item.0 }}"
loop: "{{newlist | zip(newlist) | list }}"
Ansible cisco ios,更改接口上的 vlan
我只是初学者(ansible 2.7.7),还有很多文献要研究,但希望以后能完全学会
现在我正在尝试在剧本中写下以下内容
处于“线路协议已关闭”状态的端口上接收或发送的数据包数为0
运行 端口“switchport access vlan 537”上的命令
我可以在ios_facts中获取端口状态,但是没有关于计数器的信息。你能在剧本上告诉我吗?我该如何实施?
- name: Collect IOS facts
hosts: ciscoswitch
tasks:
- name: Facts
ios_command:
commands: show interfaces counters | i 0 0
register: ios_comm_result
它的观点:
{
"changed": false,
"failed": false,
"stdout": [
"Fa0/6 0 0 0 0 \nFa0/7 0 0 0 0 \nFa0/8 0 0 0 0 \nGi0/2 0 0 0 0 \nFa0/6 0 0 0 0 \nFa0/7 0 0 0 0 \nFa0/8 0 0 0 0 \nGi0/2 0 0 0 0"
],
"stdout_lines": [
[
"Fa0/6 0 0 0 0 ",
"Fa0/7 0 0 0 0 ",
"Fa0/8 0 0 0 0 ",
"Gi0/2 0 0 0 0 ",
"Fa0/6 0 0 0 0 ",
"Fa0/7 0 0 0 0 ",
"Fa0/8 0 0 0 0 ",
"Gi0/2 0 0 0 0"
]
]
}
我如何解析寄存器 ios_comm_result 并发送命令以更改寄存器结果中的端口?
这是一个较旧的 post,所以您可能已经明白了,但这里有一个代码示例:
tasks:
- name: Facts
ios_command:
commands: show interfaces counters | i 0 0
register: ios_comm_result
- name: get a list of ports to modify
set_fact:
newlist: "{{newlist + [item.split()[0]]}}"
with_items: "{{ios_comm_result.stdout_lines}}"
- name: Apply vlan command
ios_config:
lines:
- "sw acc vlan 537"
parents: "int {{ item.0 }}"
loop: "{{newlist|zip(nMatches)|list }}"
Post Tom Klimek - 是正确的,但在语法上有一些小错误 正确:
- name: Collect IOS facts
hosts: Switch
tasks:
- name: Facts
ios_command:
commands: show interfaces counters | i 0 0
register: ios_comm_result
- name: get a list of ports to modify
set_fact:
newlist: "{{(newlist | default([])) + [item.split()[0]]}}"
with_items: "{{ios_comm_result.stdout_lines}}"
- name: Apply vlan command
ios_config:
lines:
- "sw acc vlan 998"
parents: "int {{ item.0 }}"
loop: "{{newlist | zip(newlist) | list }}"