Skip to content

Commit 6adc028

Browse files
authored
Merge pull request spantaleev#1313 from GoMatrixHosting/gomatrixhosting-testing
Gomatrixhosting testing
2 parents d38c0e1 + 71b404d commit 6adc028

20 files changed

+138
-128
lines changed

roles/matrix-awx/tasks/backup_server.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424
mode: '0660'
2525
tags: use-survey
2626

27-
- name: Collect AWX admin token the hard way!
28-
delegate_to: 127.0.0.1
29-
shell: |
30-
curl -sku {{ tower_username }}:{{ tower_password }} -H "Content-Type: application/json" -X POST -d '{"description":"Tower CLI", "application":null, "scope":"write"}' https://{{ tower_host }}/api/v2/users/1/personal_tokens/ | jq '.token' | sed -r 's/\"//g'
31-
register: tower_token
32-
no_log: True
33-
tags: use-survey
34-
3527
- name: Recreate 'Backup Server' job template
3628
delegate_to: 127.0.0.1
3729
awx.awx.tower_job_template:
@@ -49,8 +41,8 @@
4941
become_enabled: yes
5042
state: present
5143
verbosity: 1
52-
tower_host: "https://{{ tower_host }}"
53-
tower_oauthtoken: "{{ tower_token.stdout }}"
44+
tower_host: "https://{{ awx_host }}"
45+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
5446
validate_certs: yes
5547
tags: use-survey
5648

@@ -90,6 +82,15 @@
9082
command: borgmatic -c /root/.config/borgmatic/config_2.yaml
9183
when: matrix_awx_backup_enabled|bool
9284

85+
- name: Delete the AWX session token for executing modules
86+
awx.awx.tower_token:
87+
description: 'AWX Session Token'
88+
scope: "write"
89+
state: absent
90+
existing_token_id: "{{ awx_session_token.ansible_facts.tower_token.id }}"
91+
tower_host: "https://{{ awx_host }}"
92+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
93+
9394
- name: Set boolean value to exit playbook
9495
set_fact:
9596
end_playbook: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
- name: Create a AWX session token for executing modules
3+
awx.awx.tower_token:
4+
description: 'AWX Session Token'
5+
scope: "write"
6+
state: present
7+
tower_host: "https://{{ awx_host }}"
8+
tower_oauthtoken: "{{ awx_master_token }}"
9+
register: awx_session_token
10+
no_log: True

roles/matrix-awx/tasks/create_user.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
/usr/local/bin/matrix-synapse-register-user {{ new_username | quote }} {{ new_password | quote }} {{ admin_bool }}
2424
register: cmd
2525

26+
- name: Delete the AWX session token for executing modules
27+
awx.awx.tower_token:
28+
description: 'AWX Session Token'
29+
scope: "write"
30+
state: absent
31+
existing_token_id: "{{ awx_session_token.ansible_facts.tower_token.id }}"
32+
tower_host: "https://{{ awx_host }}"
33+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
34+
2635
- name: Result
2736
debug: msg="{{ cmd.stdout }}"
2837

roles/matrix-awx/tasks/customise_website_access_export.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@
7777
mode: '0660'
7878
when: customise_base_domain_website is undefined
7979

80-
- name: Collect AWX admin token the hard way!
81-
delegate_to: 127.0.0.1
82-
shell: |
83-
curl -sku {{ tower_username }}:{{ tower_password }} -H "Content-Type: application/json" -X POST -d '{"description":"Tower CLI", "application":null, "scope":"write"}' https://{{ tower_host }}/api/v2/users/1/personal_tokens/ | jq '.token' | sed -r 's/\"//g'
84-
register: tower_token
85-
no_log: True
86-
8780
- name: Recreate 'Configure Website + Access Export' job template
8881
delegate_to: 127.0.0.1
8982
awx.awx.tower_job_template:
@@ -101,8 +94,8 @@
10194
become_enabled: yes
10295
state: present
10396
verbosity: 1
104-
tower_host: "https://{{ tower_host }}"
105-
tower_oauthtoken: "{{ tower_token.stdout }}"
97+
tower_host: "https://{{ awx_host }}"
98+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
10699
validate_certs: yes
107100
when: customise_base_domain_website is defined
108101

@@ -123,8 +116,8 @@
123116
become_enabled: yes
124117
state: present
125118
verbosity: 1
126-
tower_host: "https://{{ tower_host }}"
127-
tower_oauthtoken: "{{ tower_token.stdout }}"
119+
tower_host: "https://{{ awx_host }}"
120+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
128121
validate_certs: yes
129122
when: customise_base_domain_website is undefined
130123

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
- name: Delete the AWX session token for executing modules
3+
awx.awx.tower_token:
4+
description: 'AWX Session Token'
5+
scope: "write"
6+
state: absent
7+
existing_token_id: "{{ awx_session_token.ansible_facts.tower_token.id }}"
8+
tower_host: "https://{{ awx_host }}"
9+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"

roles/matrix-awx/tasks/export_server.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
units: days
2525
unique: yes
2626

27+
- name: Delete the AWX session token for executing modules
28+
awx.awx.tower_token:
29+
description: 'AWX Session Token'
30+
scope: "write"
31+
state: absent
32+
existing_token_id: "{{ awx_session_token.ansible_facts.tower_token.id }}"
33+
tower_host: "https://{{ awx_host }}"
34+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
35+
2736
- name: Set boolean value to exit playbook
2837
set_fact:
2938
end_playbook: true

roles/matrix-awx/tasks/load_hosting_and_org_variables.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
file: '/var/lib/awx/projects/hosting/hosting_vars.yml'
1010
no_log: True
1111

12+
- name: Include AWX master token from awx_tokens.yml
13+
include_vars:
14+
file: /var/lib/awx/projects/hosting/awx_tokens.yml
15+
no_log: True

roles/matrix-awx/tasks/main.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
tags:
1818
- always
1919

20+
# Create AWX session token
21+
- include_tasks:
22+
file: "create_session_token.yml"
23+
apply:
24+
tags: always
25+
when: run_setup|bool and matrix_awx_enabled|bool
26+
tags:
27+
- always
28+
2029
# Perform a backup of the server
2130
- include_tasks:
2231
file: "backup_server.yml"
@@ -188,6 +197,15 @@
188197
tags:
189198
- setup-synapse-admin
190199

200+
# Delete AWX session token
201+
- include_tasks:
202+
file: "delete_session_token.yml"
203+
apply:
204+
tags: always
205+
when: run_setup|bool and matrix_awx_enabled|bool
206+
tags:
207+
- always
208+
191209
# Load newly formed matrix variables from AWX volume
192210
- include_tasks:
193211
file: "load_matrix_variables.yml"

roles/matrix-awx/tasks/purge_database_main.yml

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
name: dateutils
66
state: latest
77

8-
- name: Ensure dateutils, curl and jq intalled on target machine
8+
- name: Include vars in matrix_vars.yml
9+
include_vars:
10+
file: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/matrix_vars.yml'
11+
no_log: True
12+
13+
- name: Ensure curl and jq intalled on target machine
914
apt:
1015
pkg:
1116
- curl
1217
- jq
1318
state: present
1419

15-
- name: Include vars in matrix_vars.yml
16-
include_vars:
17-
file: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/matrix_vars.yml'
18-
no_log: True
19-
2020
- name: Collect before shrink size of Synapse database
2121
shell: du -sh /matrix/postgres/data
2222
register: db_size_before_stat
@@ -144,13 +144,6 @@
144144
loop: "{{ room_list_state_events.splitlines() | flatten(levels=1) }}"
145145
when: purge_mode.find("Number of events [slower]") != -1
146146

147-
- name: Collect AWX admin token the hard way!
148-
delegate_to: 127.0.0.1
149-
shell: |
150-
curl -sku {{ tower_username }}:{{ tower_password }} -H "Content-Type: application/json" -X POST -d '{"description":"Tower CLI", "application":null, "scope":"write"}' https://{{ tower_host }}/api/v2/users/1/personal_tokens/ | jq '.token' | sed -r 's/\"//g'
151-
register: tower_token
152-
no_log: True
153-
154147
- name: Adjust 'Deploy/Update a Server' job template
155148
delegate_to: 127.0.0.1
156149
awx.awx.tower_job_template:
@@ -165,8 +158,8 @@
165158
credential: "{{ member_id }} - AWX SSH Key"
166159
state: present
167160
verbosity: 1
168-
tower_host: "https://{{ tower_host }}"
169-
tower_oauthtoken: "{{ tower_token.stdout }}"
161+
tower_host: "https://{{ awx_host }}"
162+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
170163
validate_certs: yes
171164
when: (purge_mode.find("No local users [recommended]") != -1) or (purge_mode.find("Number of users [slower]") != -1) or (purge_mode.find("Number of events [slower]") != -1) or (purge_mode.find("Skip purging rooms [faster]") != -1)
172165

@@ -175,8 +168,8 @@
175168
awx.awx.tower_job_launch:
176169
job_template: "{{ matrix_domain }} - 0 - Deploy/Update a Server"
177170
wait: yes
178-
tower_host: "https://{{ tower_host }}"
179-
tower_oauthtoken: "{{ tower_token.stdout }}"
171+
tower_host: "https://{{ awx_host }}"
172+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
180173
validate_certs: yes
181174
when: (purge_mode.find("No local users [recommended]") != -1) or (purge_mode.find("Number of users [slower]") != -1) or (purge_mode.find("Number of events [slower]") != -1) or (purge_mode.find("Skip purging rooms [faster]") != -1)
182175

@@ -194,8 +187,8 @@
194187
credential: "{{ member_id }} - AWX SSH Key"
195188
state: present
196189
verbosity: 1
197-
tower_host: "https://{{ tower_host }}"
198-
tower_oauthtoken: "{{ tower_token.stdout }}"
190+
tower_host: "https://{{ awx_host }}"
191+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
199192
validate_certs: yes
200193
when: (purge_mode.find("No local users [recommended]") != -1) or (purge_mode.find("Number of users [slower]") != -1) or (purge_mode.find("Number of events [slower]") != -1) or (purge_mode.find("Skip purging rooms [faster]") != -1)
201194

@@ -231,8 +224,8 @@
231224
credential: "{{ member_id }} - AWX SSH Key"
232225
state: present
233226
verbosity: 1
234-
tower_host: "https://{{ tower_host }}"
235-
tower_oauthtoken: "{{ tower_token.stdout }}"
227+
tower_host: "https://{{ awx_host }}"
228+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
236229
validate_certs: yes
237230
when: (purge_mode.find("Perform final shrink") != -1)
238231

@@ -241,8 +234,8 @@
241234
awx.awx.tower_job_launch:
242235
job_template: "{{ matrix_domain }} - 0 - Deploy/Update a Server"
243236
wait: yes
244-
tower_host: "https://{{ tower_host }}"
245-
tower_oauthtoken: "{{ tower_token.stdout }}"
237+
tower_host: "https://{{ awx_host }}"
238+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
246239
validate_certs: yes
247240
when: (purge_mode.find("Perform final shrink") != -1)
248241

@@ -260,8 +253,8 @@
260253
credential: "{{ member_id }} - AWX SSH Key"
261254
state: present
262255
verbosity: 1
263-
tower_host: "https://{{ tower_host }}"
264-
tower_oauthtoken: "{{ tower_token.stdout }}"
256+
tower_host: "https://{{ awx_host }}"
257+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
265258
validate_certs: yes
266259
when: (purge_mode.find("Perform final shrink") != -1)
267260

@@ -308,6 +301,15 @@
308301
msg: "{{ db_size_after_stat.stdout.split('\n') }}"
309302
when: (db_size_after_stat is defined) and (purge_mode.find("Perform final shrink") != -1)
310303

304+
- name: Delete the AWX session token for executing modules
305+
awx.awx.tower_token:
306+
description: 'AWX Session Token'
307+
scope: "write"
308+
state: absent
309+
existing_token_id: "{{ awx_session_token.ansible_facts.tower_token.id }}"
310+
tower_host: "https://{{ awx_host }}"
311+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
312+
311313
- name: Set boolean value to exit playbook
312314
set_fact:
313315
end_playbook: true

roles/matrix-awx/tasks/purge_media_main.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
- name: Ensure dateutils and curl is installed in AWX
2+
- name: Ensure dateutils is installed in AWX
33
delegate_to: 127.0.0.1
44
yum:
55
name: dateutils
@@ -90,6 +90,15 @@
9090
msg: "{{ remote_media_size_after.stdout.split('\n') }}"
9191
when: matrix_purge_media_type == "Remote Media"
9292

93+
- name: Delete the AWX session token for executing modules
94+
awx.awx.tower_token:
95+
description: 'AWX Session Token'
96+
scope: "write"
97+
state: absent
98+
existing_token_id: "{{ awx_session_token.ansible_facts.tower_token.id }}"
99+
tower_host: "https://{{ awx_host }}"
100+
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
101+
93102
- name: Set boolean value to exit playbook
94103
set_fact:
95104
end_playbook: true

0 commit comments

Comments
 (0)