gpt4 book ai didi

Ansible 事实排序数据 (Cisco ACI)

转载 作者:行者123 更新时间:2023-12-04 03:25:19 27 4
gpt4 key购买 nike

我正在尝试从 Cisco ACI 获取路由表。我收到重复的路线。有办法解决它们吗?

例子:

        "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

关于Ansible 事实排序数据 (Cisco ACI),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67704512/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com