-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdict_filters.yml
207 lines (185 loc) · 4.28 KB
/
dict_filters.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
---
# Test filter_plugins/dict_filters
- name: dict_filters
hosts: localhost
gather_facts: false
vars:
dict1:
a: 1
b: 2
dict2:
a: 1
b: 2
c: 3
dict3:
a: [1]
b: [2]
c: [3]
add_this:
c: 9
ports:
webui: 7200
webadmin: 7209
core_api: 7201
stock_api: 7204
import_export: 7207
ports_attrs1: [webui, core_api]
dict4: {
"a":{
"r": 1,
"s": 2,
"t": 3
},
"b":{
"u": 1,
"v": {
"x": 1,
"y": 2,
"z": [3, 4, 5]
},
"w": 3
}
}
dict5:
c:
ip: 10.1.0.19
mac: 88:88:88:88:88:80
a:
ip: 10.1.0.17
mac: 88:88:88:88:88:81
b:
ip: 10.1.0.18
mac: 88:88:88:88:88:82
list1: ["key1", "value1"]
list2:
- ["key1", "value1"]
- ["key2", "value2"]
- ["key3", "value3"]
list3:
- ip: 10.1.0.19
mask: 255.255.255.0
mac: 88:88:88:88:88:80
- ip: 10.1.0.17
mask: 255.255.255.0
mac: 88:88:88:88:88:81
- ip: 10.1.0.18
mask: 255.255.255.0
mac: 88:88:88:88:88:82
list3_attrs1: [ip, mask]
list4:
- country: England
capital: London
population: 9
- country: USA
capital: Washington
population: 8
- country: Australia
capital: Canberra
population: 0.4
list4_attrs1: [capital, population]
tasks:
- debug:
var: added_dict
vars:
added_dict: "{{ dict1|dict_add_dict(add_this) }}"
tags: added_dict
- debug:
var: del_key
vars:
del_key: "{{ dict2|dict_del_key('b') }}"
tags: del_key
- debug:
var: merge_dict
vars:
merge_dict: "{{ dict1|dict_merge(dict2) }}"
tags: merge_dict
- debug:
var: merge_dict
vars:
merge_dict: "{{ dict1|dict_merge(dict3) }}"
tags: merge_dict
- debug:
var: merge_dict_lossless
vars:
merge_dict_lossless: "{{ dict1|dict_merge_lossless(dict3) }}"
tags: merge_dict_lossless
- debug:
var: appended_dict
vars:
appended_dict: "{{ dict2|dict_add_dict(add_this, True) }}"
tags: appended_dict
- debug:
var: replaced_dict
vars:
replaced_dict: "{{ dict2|dict_add_dict(add_this) }}"
tags: replaced_dict
- debug:
var: appended_dict_to_list
vars:
appended_dict_to_list: "{{ dict3|dict_add_dict(add_this, True) }}"
tags: appended_dict_to_list
- debug:
var: prefixed_keys
vars:
prefixed_keys: "{{ ports|dict_prefix_keys('staging_') }}"
tags: prefixed_keys
- debug:
var: dict4_flatten
vars:
dict4_flatten: "{{ dict4|dict_flatten }}"
tags: dict_flatten
- debug:
var: dict4_flatten
vars:
dict4_flatten: "{{ dict4|dict_flatten(separator='_') }}"
tags: dict_flatten
- debug:
var: dict5_sortbysubkey
vars:
dict5_sortbysubkey: "{{ dict5|dict_sortbysubkey('ip') }}"
tags: dict_sortbysubkey
- debug:
var: dict1_2list
vars:
dict1_2list: "{{ dict1|dict2list }}"
tags: dict1_2list
- debug:
var: list1_2dict
vars:
list1_2dict: "{{ list1|item2dict }}"
tags: list1_2dict
- debug:
var: list2_2dict
vars:
list2_2dict: "{{ list2|map('item2dict')|list }}"
tags: list2_2dict
- debug:
var: list2_2dict
vars:
list2_2dict: "{{ dict(list2) }}"
tags: list2_2dict
- debug:
var: dict_select_list
vars:
dict_select_list: "{{ dict5|dict_select_list(['b', 'c']) }}"
tags: dict_select_list
- debug:
var: dict2hash
vars:
dict2hash: "{{ dict4|dict2hash }}"
tags: dict2hash
- debug:
var: result
vars:
result: "{{ ports|dict_attrs(ports_attrs1) }}"
tags: dict_attrs1
- debug:
var: result
vars:
result: "{{ list3|map('dict_attrs', list3_attrs1)|list }}"
tags: dict_attrs2
- debug:
var: result
vars:
result: "{{ list4|items2dict(key_name='capital', value_name='population') }}"
tags: dict_items2dict