-
Notifications
You must be signed in to change notification settings - Fork 6
/
test-json.yml
69 lines (58 loc) · 1.85 KB
/
test-json.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
# ansible-galaxy collection install ansible.utils
# ansible-playbook test-json.yml
- name: Play around with JSON inputs
hosts: localhost
connection: local
become: false
gather_facts: false
vars:
input: "{{ lookup('file','files/ospf.json') | from_json }}"
tasks:
- name: Create interfaces Dictionary
set_fact:
interfaces: "{{ input.parsed.interfaces }}"
- name: Print out interfaces
debug:
var: interfaces
- name: Print out flatten interfaces input
debug:
msg: "{{ lookup('ansible.utils.to_paths', interfaces) }}"
- name: TEST 1
block:
- name: Loop over interfaces
include_tasks: test-json-tasks-1.yml
with_items: "{{ interfaces | dict2items }}"
- name: TEST 2
block:
- name: Create neighbors dictionary (this is now per interface)
set_fact:
neighbors: "{{ interfaces | json_query('*.neighbors') }}"
- name: Print out neighbors
debug:
msg: "{{ neighbors }}"
- name: Loop over neighbors
include_tasks: test-json-tasks-2.yml
with_items: "{{ neighbors }}"
loop_control:
loop_var: data
- name: TEST 3
block:
- name: Loop over neighbors
include_tasks: test-json-tasks-3.yml
with_items: "{{ neighbors }}"
loop_control:
loop_var: data
- name: TEST 4
block:
- name: Loop with deep json_query
debug:
var: "{{ item }}"
with_items: "{{ input | json_query('parsed.interfaces.*.neighbors[].*.[address, state]') }}"
- name: TEST 5
block:
- name: Loop over neighbors and validate data with a schema
include_tasks: test-json-tasks-4.yml
with_items: "{{ neighbors }}"
loop_control:
loop_var: data