matrix-docker-ansible-deploy/roles/matrix-awx/tasks/set_variables_dimension.yml

106 lines
3.8 KiB
YAML
Raw Normal View History

2021-10-10 05:23:49 +00:00
---
2021-08-13 08:05:57 +00:00
- name: Include vars in matrix_vars.yml
include_vars:
file: '{{ awx_cached_matrix_vars }}'
no_log: true
2021-08-13 08:05:57 +00:00
- name: Install jq and curl on remote machine
apt:
name:
2021-08-13 08:05:57 +00:00
- jq
- curl
state: present
2021-12-06 03:54:31 +00:00
- name: Collect access token of @admin-dimension user
2021-08-13 08:05:57 +00:00
shell: |
2022-02-27 09:40:20 +00:00
curl -X POST --header 'Content-Type: application/json' -d '{"identifier": {"type": "m.id.user","user": "admin-dimension"}, "password": "{{ awx_dimension_user_password }}", "type": "m.login.password"}' 'https://matrix.{{ matrix_domain }}/_matrix/client/r0/login' | jq '.access_token'
register: awx_dimension_user_access_token
2021-08-13 08:05:57 +00:00
- name: Record Synapse variables locally on AWX
delegate_to: 127.0.0.1
lineinfile:
path: '{{ awx_cached_matrix_vars }}'
regexp: "^#? *{{ item.key | regex_escape() }}:"
line: "{{ item.key }}: {{ item.value }}"
insertafter: '# Dimension Settings Start'
with_dict:
'matrix_dimension_enabled': '{{ matrix_dimension_enabled }}'
2022-02-27 09:40:20 +00:00
'matrix_dimension_access_token': '"{{ awx_dimension_user_access_token.stdout[1:-1] }}"'
2021-08-13 08:05:57 +00:00
- name: Set final users list if users are defined
set_fact:
2021-10-10 06:10:06 +00:00
awx_dimension_users_final: "{{ awx_dimension_users }}"
2021-10-10 08:16:31 +00:00
when: awx_dimension_users | length > 0
2021-08-13 08:05:57 +00:00
- name: Set final users list if no users are defined
set_fact:
2021-10-10 06:10:06 +00:00
awx_dimension_users_final: '@dimension:{{ matrix_domain }}'
2021-10-10 08:16:31 +00:00
when: awx_dimension_users | length == 0
2021-08-13 08:05:57 +00:00
- name: Remove Dimension Users
delegate_to: 127.0.0.1
replace:
path: '{{ awx_cached_matrix_vars }}'
regexp: '^ - .*\n'
after: 'matrix_dimension_admins:'
before: '# Dimension Settings End'
- name: Set Dimension Users Header
delegate_to: 127.0.0.1
lineinfile:
path: '{{ awx_cached_matrix_vars }}'
insertbefore: '# Dimension Settings End'
line: "matrix_dimension_admins:"
- name: Set Dimension Users
delegate_to: 127.0.0.1
lineinfile:
path: '{{ awx_cached_matrix_vars }}'
insertafter: '^matrix_dimension_admins:'
line: ' - "{{ item }}"'
2021-10-10 06:10:06 +00:00
with_items: "{{ awx_dimension_users_final.splitlines() }}"
2021-08-13 08:05:57 +00:00
- name: Record Dimension Custom variables locally on AWX
delegate_to: 127.0.0.1
lineinfile:
path: '{{ awx_cached_matrix_vars }}'
regexp: "^#? *{{ item.key | regex_escape() }}:"
line: "{{ item.key }}: {{ item.value }}"
2021-10-10 06:10:06 +00:00
insertbefore: '# Dimension Settings End'
2021-08-13 08:05:57 +00:00
with_dict:
2021-10-10 06:10:06 +00:00
'awx_dimension_users': '{{ awx_dimension_users.splitlines() | to_json }}'
2021-08-13 08:05:57 +00:00
- name: Save new 'Configure Dimension' survey.json to the AWX tower, template
delegate_to: 127.0.0.1
template:
src: 'roles/matrix-awx/surveys/configure_dimension.json.j2'
dest: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}//configure_dimension.json'
- name: Copy new 'Configure Dimension' survey.json to target machine
copy:
src: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/configure_dimension.json'
dest: '/matrix/awx/configure_dimension.json'
2021-08-13 08:05:57 +00:00
mode: '0660'
- name: Recreate 'Configure Dimension' job template
delegate_to: 127.0.0.1
awx.awx.tower_job_template:
name: "{{ matrix_domain }} - 1 - Configure Dimension"
description: "Configure Dimension, the self-hosted integrations server."
extra_vars: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/extra_vars.json') }}"
job_type: run
job_tags: "start,setup-all,setup-dimension"
inventory: "{{ member_id }}"
project: "{{ member_id }} - Matrix Docker Ansible Deploy"
playbook: setup.yml
credential: "{{ member_id }} - AWX SSH Key"
survey_enabled: true
survey_spec: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/configure_dimension.json') }}"
become_enabled: true
2021-08-13 08:05:57 +00:00
state: present
verbosity: 1
tower_host: "https://{{ awx_host }}"
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
validate_certs: true