-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_services.yml
106 lines (94 loc) · 3.57 KB
/
list_services.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
---
# Gets variables from all web applications recursively (for Homer and SWAG)
- name: Empty the variables (In case the task is called twice)
ansible.builtin.set_fact:
web_services_to_build: []
when: web_services_to_build is defined
- name: Empty the variables (In case the task is called twice)
ansible.builtin.set_fact:
roleswithvariables_to_build: []
when: roleswithvariables_to_build is defined
# - name: Web Container Roles Prepare the data for all the webservices hosted as a webservice
# block:
- name: Get a list of web containers to be hosted as a web service and displayed by homer
delegate_to: localhost
become: false
find:
paths: "{{ webservices_paths }}"
file_type: directory
excludes: "{{ include_role_vars }}"
register: webservices
- name: Debug webservices variable
debug:
var: webservices
- name: Get a List of roles with other common variables to include
delegate_to: localhost
become: false
find:
paths:
- "{{ playbook_dir }}/roles/"
file_type: directory
patterns: "{{ include_role_vars | flatten | join('') }}"
recurse: yes
register: roleswithvariables
- name: Debug roleswithvariables variable
debug:
var: roleswithvariables
# - name: Include all main.yml files for webservices and homer
# block:
- name: Including webservice main.yml
include_vars:
dir: "{{ playbook_dir }}/{{ item.path }}/defaults"
files_matching: main.yml
name: "{{ item.path.split('/')[-1] }}"
with_items: "{{ webservices.files }}"
- name: Including the role to build main.yml
include_vars:
dir: "{{ playbook_dir }}/roles/homer/defaults"
files_matching: main.yml
name: "{{ item.path.split('/')[-1] }}"
with_items: "{{ roleswithvariables.files }}"
- name: Build the key, value pairs that the webservices dictionary consits of
ansible.builtin.set_fact:
web_services_to_build: "{{ web_services_to_build | default({}) |
combine({
item.path.split('/')[-1]:
{
'role_name' : item.path.split('/')[-1],
'path' : item.path,
'tag_primary' : item.path.split('/')[-1],
'tag_secondary' : item.path.split('/')[1],
'logo' : '/assets/tools/homer-icons/' + item.path.split('/')[-1] + '.png',
'ip_address' : this_current_var.ip_address | default(''),
'swag_address': this_current_var.swag_address | default(''),
'name' : this_current_var.dashboard_name | default(item.path.split('/')[-1] | title),
'url' : this_current_var.url | default(''),
'category' : this_current_var.homer_category | default ('')
}
})
}}"
vars:
this_current_var: "{{ lookup('vars', item.path.split('/')[-1]) }}"
with_items: "{{ webservices.files }}"
- name: Debug web_services_to_build variable
debug:
var: web_services_to_build
- name: Build the key, value pairs for roleswithvariables
ansible.builtin.set_fact:
roleswithvariables_to_build: "{{ roleswithvariables_to_build | default({}) |
combine({
item.path.split('/')[-1]:
{
'role_name': item.path.split('/')[-1],
'ip_address': this_current.ip_address | default(''),
'swag_address': this_current.swag_address | default(''),
'url': this_current.url | default('')
}
})
}}"
vars:
this_current: "{{ lookup('vars', item.path.split('/')[-1]) }}"
with_items: "{{ roleswithvariables.files }}"
- name: Debug roleswithvariables_to_build variable
debug:
var: roleswithvariables_to_build