--- - name: Check for specified PostgreSQL configuration k8s_info: kind: Secret namespace: '{{ ansible_operator_meta.namespace }}' name: '{{ postgres_configuration_secret }}' register: _custom_pg_config_resources when: postgres_configuration_secret | length no_log: "{{ no_log }}" - name: Check for default PostgreSQL configuration k8s_info: kind: Secret namespace: '{{ ansible_operator_meta.namespace }}' name: '{{ ansible_operator_meta.name }}-postgres-configuration' register: _default_pg_config_resources no_log: "{{ no_log }}" - name: Check for specified old PostgreSQL configuration secret k8s_info: kind: Secret namespace: '{{ ansible_operator_meta.namespace }}' name: '{{ old_postgres_configuration_secret }}' register: _custom_old_pg_config_resources when: old_postgres_configuration_secret | length no_log: "{{ no_log }}" - name: Check for default old PostgreSQL configuration k8s_info: kind: Secret namespace: '{{ ansible_operator_meta.namespace }}' name: '{{ ansible_operator_meta.name }}-old-postgres-configuration' register: _default_old_pg_config_resources no_log: "{{ no_log }}" - name: Set old PostgreSQL configuration set_fact: # yamllint disable-line rule:line-length old_pg_config: '{{ _custom_old_pg_config_resources["resources"] | default([]) | length | ternary(_custom_old_pg_config_resources, _default_old_pg_config_resources) }}' # noqa 204 - name: Set proper database name when migrating from old deployment set_fact: database_name: "{{ old_pg_config['resources'][0]['data']['database'] | b64decode }}" database_username: "{{ old_pg_config['resources'][0]['data']['username'] | b64decode }}" when: - old_pg_config['resources'] is defined - old_pg_config['resources'] | length no_log: "{{ no_log }}" - name: Set default postgres image set_fact: _default_postgres_image: "{{ _postgres_image }}:{{_postgres_image_version }}" - name: Set PostgreSQL configuration set_fact: _pg_config: '{{ _custom_pg_config_resources["resources"] | default([]) | length | ternary(_custom_pg_config_resources, _default_pg_config_resources) }}' no_log: "{{ no_log }}" - name: Set user provided postgres image set_fact: _custom_postgres_image: "{{ postgres_image }}:{{ postgres_image_version }}" when: - postgres_image | default([]) | length - postgres_image_version is defined and postgres_image_version != '' - name: Set Postgres image URL set_fact: _postgres_image: "{{ _custom_postgres_image | default(lookup('env', 'RELATED_IMAGE_AWX_POSTGRES')) | default(_default_postgres_image, true) }}" - block: - name: Create Database configuration k8s: apply: true definition: "{{ lookup('template', 'secrets/postgres_secret.yaml.j2') }}" no_log: "{{ no_log }}" - name: Read Database Configuration k8s_info: kind: Secret namespace: '{{ ansible_operator_meta.namespace }}' name: '{{ ansible_operator_meta.name }}-postgres-configuration' register: _generated_pg_config_resources no_log: "{{ no_log }}" 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) }}' no_log: "{{ no_log }}" - name: Set actual postgres configuration secret used set_fact: __postgres_configuration_secret: "{{ pg_config['resources'][0]['metadata']['name'] }}" - 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 }}" awx_postgres_sslmode: "{{ pg_config['resources'][0]['data']['sslmode'] | default('prefer'|b64encode) | b64decode }}" awx_postgres_target_session_attrs: "{{ pg_config['resources'][0]['data']['target_session_attrs'] | default('') | b64decode }}" no_log: "{{ no_log }}" - name: Set database as managed set_fact: managed_database: "{{ pg_config['resources'][0]['data']['type'] | default('') | b64decode == 'managed' }}"