如何解决Ansible 事实排序数据 (Cisco ACI)
我正在尝试从 Cisco ACI 获取路由表。我收到重复的路线。有没有办法把它们整理出来?
示例:
"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,例如
const {pipe,sortBy,identity,groupWith,map,juxt,head,last} = R
const nonConsecutives = pipe (
sortBy (identity),groupWith ((a,b) => b - a <= 1),map (juxt ([head,last]))
)
console .log (
nonConsecutives ([2,3,4,5,9,8,10,13])
)
给予
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.27.1/ramda.min.js"></script>
问:“仅获取带有 /24 的地址”
A:使用过滤器 ipaddr,例如
- debug:
msg: "{{ data_struc|unique }}"
给予
msg:
- 10.127.32.70/32
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。