mirror of
https://github.com/ansible/awx-operator.git
synced 2026-03-26 21:33:14 +00:00
If a user provide its own secret by using the `tower_postgres_configuration_secret` use this variable, else try to use `<instance>-postgres-configuration` secret. Else create one and use a local database.
54 lines
2.0 KiB
YAML
54 lines
2.0 KiB
YAML
---
|
|
- name: Check for specified PostgreSQL configuration
|
|
k8s_info:
|
|
kind: Secret
|
|
namespace: '{{ meta.namespace }}'
|
|
name: '{{ tower_postgres_configuration_secret }}'
|
|
register: _custom_pg_config_resources
|
|
when: tower_postgres_configuration_secret | length
|
|
|
|
- name: Check for default PostgreSQL configuration
|
|
k8s_info:
|
|
kind: Secret
|
|
namespace: '{{ meta.namespace }}'
|
|
name: '{{ meta.name }}-postgres-configuration'
|
|
register: _default_pg_config_resources
|
|
|
|
- name: Set PostgreSQL configuration
|
|
set_fact:
|
|
_pg_config: '{{ _custom_pg_config_resources["resources"] | default([]) | length | ternary(_custom_pg_config_resources, _default_pg_config_resources) }}'
|
|
|
|
- block:
|
|
- name: Create Database configuration
|
|
k8s:
|
|
apply: true
|
|
definition: "{{ lookup('template', 'tower_postgres_secret.yaml.j2') }}"
|
|
|
|
- name: Read Database Configuration
|
|
k8s_info:
|
|
kind: Secret
|
|
namespace: '{{ meta.namespace }}'
|
|
name: '{{ meta.name }}-postgres-configuration'
|
|
register: _generated_pg_config_resources
|
|
|
|
when: not _pg_config['resources'] | default([]) | length
|
|
|
|
- name: Set PostgreSQL Configuration
|
|
set_fact:
|
|
pg_config: '{{ _generated_pg_config_resources["resources"] | default([]) | length | ternary(_generated_pg_config_resources, _pg_config) }}'
|
|
|
|
- name: Create Database if no database is specified
|
|
k8s:
|
|
apply: true
|
|
definition: "{{ lookup('template', 'tower_postgres.yaml.j2') }}"
|
|
when:
|
|
- pg_config['resources'][0]['data']['type'] | default('') | b64decode == 'managed'
|
|
|
|
- name: Store Database Configuration
|
|
set_fact:
|
|
awx_postgres_user: "{{ pg_config['resources'][0]['data']['username'] | b64decode }}"
|
|
awx_postgres_pass: "{{ pg_config['resources'][0]['data']['password'] | b64decode }}"
|
|
awx_postgres_database: "{{ pg_config['resources'][0]['data']['database'] | b64decode }}"
|
|
awx_postgres_port: "{{ pg_config['resources'][0]['data']['port'] | b64decode }}"
|
|
awx_postgres_host: "{{ pg_config['resources'][0]['data']['host'] | b64decode }}"
|