Ansible 事实排序数据 (Cisco ACI)
Ansible fact sort data (Cisco ACI)
我正在尝试从 Cisco ACI 获取路由 table。我收到重复的路线。有办法解决吗?
示例:
"10.127.32.70/32",
"10.127.32.70/32",
"10.127.32.70/32",
"10.127.32.70/32",
"10.127.32.70/32",
"10.127.32.70/32"
重复过滤后:
"10.127.32.70/32"
- name: Get Route table (vars tenant and VRF)
aci_rest:
<<: *aci_login
path: api/node/class/uribv4Nexthop.json?query-target-filter=wcard(uribv4Nexthop.dn,"sys/uribv4/dom\-C_Lab:LAB_VRF/db\-rt")
method: "get"
register: response
# - debug:
# var: response
- name: Create a subnet list item
set_fact:
array_content: "{{ item['uribv4Nexthop']['attributes']['addr'] }}"
with_items:
- "{{ response['imdata'] }}"
register: array_of_contents
- name: Make a list with all the subnet items
set_fact:
data_struc: "{{ array_of_contents.results | map(attribute='ansible_facts.array_content') | list }}"
- debug:
var: data_struc
使用过滤器 unique,例如
- debug:
msg: "{{ data_struc|unique }}"
给予
msg:
- 10.127.32.70/32
问:"仅使用 /24 获取地址"
A:使用过滤器 ipaddr,例如
- set_fact:
prefix_24: "{{ prefix_24|d([]) + [item] }}"
loop: "{{ data_struc|unique }}"
when: item|ipaddr('prefix') == 24
vars:
data_struc:
- 10.127.32.70/32
- 10.127.32.71/24
- 10.127.32.71/24
- 10.127.32.72/32
给予
prefix_24:
- 10.127.32.71/24
我正在尝试从 Cisco ACI 获取路由 table。我收到重复的路线。有办法解决吗?
示例:
"10.127.32.70/32",
"10.127.32.70/32",
"10.127.32.70/32",
"10.127.32.70/32",
"10.127.32.70/32",
"10.127.32.70/32"
重复过滤后:
"10.127.32.70/32"
- name: Get Route table (vars tenant and VRF)
aci_rest:
<<: *aci_login
path: api/node/class/uribv4Nexthop.json?query-target-filter=wcard(uribv4Nexthop.dn,"sys/uribv4/dom\-C_Lab:LAB_VRF/db\-rt")
method: "get"
register: response
# - debug:
# var: response
- name: Create a subnet list item
set_fact:
array_content: "{{ item['uribv4Nexthop']['attributes']['addr'] }}"
with_items:
- "{{ response['imdata'] }}"
register: array_of_contents
- name: Make a list with all the subnet items
set_fact:
data_struc: "{{ array_of_contents.results | map(attribute='ansible_facts.array_content') | list }}"
- debug:
var: data_struc
使用过滤器 unique,例如
- debug:
msg: "{{ data_struc|unique }}"
给予
msg:
- 10.127.32.70/32
问:"仅使用 /24 获取地址"
A:使用过滤器 ipaddr,例如
- set_fact:
prefix_24: "{{ prefix_24|d([]) + [item] }}"
loop: "{{ data_struc|unique }}"
when: item|ipaddr('prefix') == 24
vars:
data_struc:
- 10.127.32.70/32
- 10.127.32.71/24
- 10.127.32.71/24
- 10.127.32.72/32
给予
prefix_24:
- 10.127.32.71/24