-
Notifications
You must be signed in to change notification settings - Fork 0
/
play_cisco_restconf_interfaces_02.yml
53 lines (49 loc) · 1.61 KB
/
play_cisco_restconf_interfaces_02.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
- name: "PLAY 1: TESTING RESTCONF"
hosts: localhost
connection: local
gather_facts: false
vars:
cisco_sandbox: "sandbox-iosxe-latest-1.cisco.com"
cisco_username: "admin"
cisco_password: "C1sco12345"
cisco_restconf_native_endpoint: "/restconf/data/native/interface"
tasks:
- name: PULL INFO
ansible.builtin.uri:
url: "https://{{ cisco_sandbox }}{{ cisco_restconf_native_endpoint }}"
method: GET
user: "{{ cisco_username }}"
password: "{{ cisco_password }}"
return_content: true
headers:
Accept: "application/yang-data+json"
validate_certs: false
register: result_api
- name: SETFACT STRING TO DICT
set_fact:
result: "{{ result_api.content | from_yaml }}"
- name: PRINT RESULT 1st LOOP
debug:
msg: "{{ item.key }} {{ item.value[0].name }} {{ item.value|length }}"
loop: "{{ result['Cisco-IOS-XE-native:interface'] | dict2items }}"
loop_control:
label: "{{ item.key }}"
- name: PRINT RESULT LOOP of LOOP
debug:
msg: "{{ item.port_name }}{{ item.port_id }} - {{ item.full|length }} = {{ item.full }}"
loop: >-
{%- set results = [] -%}
{%- for item in result['Cisco-IOS-XE-native:interface']|dict2items -%}
{%- for port in item.value -%}
{%- set _ = results.append({
"full": port,
"port_id": port.name,
"port_name": item.key
}) %}
{%- endfor -%}
{%- endfor -%}
{{ results }}
loop_control:
label: "{{ item.port_name }}{{ item.port_id }}"
...