blob: e4e4fb6fd5e9b98da868964284c8ed3fe1780279 (
plain)
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
|
---
##
# Warn if log level is high
##
- name: Warn if log level is high
debug:
msg: "{{ msg.split('\n') }}"
verbosity: 3
vars:
msg: |
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Log level is HIGH ! !!
!! Some sensitive data may be visible to everyone. !!
!! Don't forget to clean the task output ! !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
##
# get the config
##
- name: get artifact_src if we refer to a previous one
when: artifacts_src is defined
uri:
url: "{{ artifacts_src }}"
headers:
PRIVATE-TOKEN: "{{ gitlab.private_token }}"
dest: "{{ playbook_dir }}/artifacts.zip"
- name: unzip get_artifact archive
when: artifacts_src is defined or artifacts_bin is defined
unarchive:
src: "{{ playbook_dir }}/artifacts.zip"
dest: "{{ playbook_dir }}"
remote_src: "yes"
- name: delete archive
file:
path: "{{ playbook_dir }}/artifacts.zip"
state: absent
- name: create artifacts folders
file:
path: "{{ item }}"
state: directory
mode: 0775
when: item[-1] == '/'
with_items: "{{ vars[lookup( 'env', 'CI_JOB_NAME')].artifacts.paths }}"
- name: ensure configs can be written
file:
path: "{{ playbook_dir }}/{{ item }}"
mode: 0660
ignore_errors: true
with_items:
- vars/pdf.yml
- vars/idf.yml
- vars/certificates.yml
- vars/vaulted_ssh_credentials.yml
- vars/ssh_gateways.yml
- name: get the infra config name
set_fact:
infra_config: "{{ config.infra | default(inventory_hostname) }}"
- name: get the infra PDF/IDF
when: infra_config != 'NONE'
block:
- name: get PDF configs
uri:
url: >-
{{ config.api }}/repository/files/{{
[config.path | default(''), 'config'] |
filepath(infra_config, '.yaml') }}?ref={{ config.branch }}
headers:
PRIVATE-TOKEN: "{{ gitlab.private_token }}"
status_code: 200
return_content: yes
register: pdf_get
- name: save PDF config
copy:
content: "{{ pdf_get.json.content | b64decode }}"
dest: "{{ playbook_dir }}/vars/pdf.yml"
force: true
mode: 0660
decrypt: false
- name: get IDF configs
uri:
url: >-
{{ config.api }}/repository/files/{{ [config.path | default(''),
'config'] | filepath('idf-', infra_config, '.yaml')
}}?ref={{ config.branch }}
headers:
PRIVATE-TOKEN: "{{ gitlab.private_token }}"
status_code: 200
return_content: yes
register: idf_get
- name: save IDF config
copy:
content: "{{ idf_get.json.content | b64decode }}"
dest: "{{ playbook_dir }}/vars/idf.yml"
force: true
mode: 0660
decrypt: false
- name: get certificate
uri:
url: >-
{{ config.api }}/repository/files/{{
[config.path | default(''), 'certificats']
| filepath(config.certificates) }}?ref={{ config.branch }}
headers:
PRIVATE-TOKEN: "{{ gitlab.private_token }}"
status_code: 200
return_content: yes
register: certs_get
when: config.certificates is defined
- name: save certificate
copy:
content: "{{ certs_get.json.content | b64decode }}"
dest: "{{ playbook_dir }}/vars/certificates.yml"
force: true
mode: 0660
decrypt: false
when: config.certificates is defined
- name: get ssh credentials
uri:
url: >-
{{ config.api }}/repository/files/{{
[config.path | default(''), 'ssh_creds'] |
filepath(config.ssh_creds | default(ansible_ssh_creds))
}}?ref={{ config.branch }}
headers:
PRIVATE-TOKEN: "{{ gitlab.private_token }}"
status_code: 200
return_content: yes
register: ssh_creds_get
when: config.ansible_ssh_creds is defined or ansible_ssh_creds is defined
- name: save ssh credentials
copy:
content: "{{ ssh_creds_get.json.content | b64decode }}"
dest: "{{ playbook_dir }}/vars/vaulted_ssh_credentials.yml"
force: true
mode: 0660
decrypt: false
when: config.ansible_ssh_creds is defined or ansible_ssh_creds is defined
- name: set ssh gateways config
uri:
url: >-
{{ config.api }}/repository/files/{{
[config.path | default(''), 'config/ssh_gateways']
| filepath(config.ssh_access) }}?ref={{ config.branch }}
headers:
PRIVATE-TOKEN: "{{ gitlab.private_token }}"
status_code: 200
return_content: yes
register: ssh_gw_get
when: config.ssh_access is defined
- name: save ssh gateways config
copy:
content: "{{ ssh_gw_get.json.content | b64decode }}"
dest: "{{ playbook_dir }}/vars/ssh_gateways.yml"
force: true
mode: 0660
decrypt: false
when: config.ssh_access is defined
- name: set basic inventory
copy:
dest: "{{ playbook_dir }}/inventory/inventory"
content: >
jumphost ansible_host={{ jumphost.server }}
ansible_user={{ jumphost.user }} pod={{ inventory_hostname }}
|