forked from CiscoDevNet/sdwan-devops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery-attach.yml
60 lines (50 loc) · 1.96 KB
/
query-attach.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
- name: Attach Templates QUERY
hosts: all
any_errors_fatal: false
connection: local
gather_facts: no
roles:
- ansible-viptela
tasks:
- name: Query Attach Template
vmanage_device_attachment:
user: "{{vmanage_user}}"
host: "{{vmanage_host}}"
password: "{{vmanage_password}}"
template: "{{ templateName }}"
state: "query"
register: attachment_results_query
- name: Create list of parameter per query
set_fact:
parameterPropertyDict: "{{ attachment_results_query.mandatory_template_variables }}"
#loop: "{{attachment_results_query}}"
- name: Create list of optional variables
set_fact:
optionalVariables: "{{ attachment_results_query.optional_template_variables }}"
- name: Init/Refresh dict of Variables
set_fact:
parameterDict: {}
- name: Populate the parameter dict and get rid of the yang variables
set_fact:
parameterDict: "{{ parameterDict | combine( { item.key : '' }) }}"
loop: "{{ parameterPropertyDict|dict2items }}"
- name: Init/Refresh new variables dict
set_fact:
mandatoryVariables: {}
- name: Getting rid of unnecessary variables from previous template queries
set_fact:
mandatoryVariables: "{{ mandatoryVariables | combine( { item.key: item.value } ) }}"
when: "{{ item.key in parameterDict or item.key in optionalVariables }}"
with_dict: "{{ variables|default({}) }}"
- name: Init/Refresh dict with current variables plus missing Variables
set_fact:
missingVariables: {}
- name: Mix Variables already available plus the new ones from the template
set_fact:
missingVariables: "{{ missingVariables \
| combine({inventory_hostname : { 'templateName': templateName, \
'variables': parameterDict | combine(mandatoryVariables) }}) }}"
- debug:
var: missingVariables
- debug:
var: optionalVariables