From 285be0faff867af7f71548fbf48fe50ee9718f72 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Fri, 5 Feb 2021 16:00:42 +0100 Subject: [PATCH] deployment_type: Introduce the new variable. --- deploy/crds/awx_v1beta1_molecule.yaml | 3 +-- roles/awx/defaults/main.yml | 4 +++- roles/awx/tasks/main.yml | 12 ++++++------ roles/awx/templates/tower.yaml.j2 | 16 ++++++++-------- roles/awx/templates/tower_config.yaml.j2 | 4 ++-- roles/awx/templates/tower_postgres.yaml.j2 | 11 +++++------ .../awx/templates/tower_postgres_secret.yaml.j2 | 4 ++-- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/deploy/crds/awx_v1beta1_molecule.yaml b/deploy/crds/awx_v1beta1_molecule.yaml index 8387b3bd..474f7e62 100644 --- a/deploy/crds/awx_v1beta1_molecule.yaml +++ b/deploy/crds/awx_v1beta1_molecule.yaml @@ -5,13 +5,12 @@ metadata: name: example-awx namespace: example-awx spec: + deployment_type: awx tower_ingress_type: ingress tower_task_privileged: false - tower_hostname: example-awx.test tower_broadcast_websocket_secret: changeme - tower_admin_user: test tower_admin_email: test@example.com tower_admin_password: changeme diff --git a/roles/awx/defaults/main.yml b/roles/awx/defaults/main.yml index f5e1a6aa..5c7cf1d1 100644 --- a/roles/awx/defaults/main.yml +++ b/roles/awx/defaults/main.yml @@ -1,4 +1,6 @@ --- +deployment_type: awx + tower_task_privileged: false tower_ingress_type: none @@ -13,7 +15,7 @@ tower_ingress_annotations: '' # certificate and key. tower_ingress_tls_secret: '' -tower_hostname: example-awx.test +tower_hostname: '{{ deployment_type }}.example.com' tower_admin_user: admin tower_admin_email: test@example.com diff --git a/roles/awx/tasks/main.yml b/roles/awx/tasks/main.yml index 01aa45f0..bcfe8b28 100644 --- a/roles/awx/tasks/main.yml +++ b/roles/awx/tasks/main.yml @@ -49,7 +49,7 @@ register: k8s_tower_secret_result when: secret_key_resources['resources'] | length < 1 -- name: Ensure configured AWX resources exist in the cluster. +- name: Ensure configured instance resources exist in the cluster. k8s: apply: yes definition: "{{ lookup('template', item) | from_yaml_all | list }}" @@ -57,28 +57,28 @@ with_items: - tower_config.yaml.j2 -- name: Apply Tower Deployment Configuration +- name: Apply Resource Deployment Configuration k8s: apply: yes definition: "{{ lookup('template', 'tower.yaml.j2') }}" register: tower_deployment_result -- name: Get the AWX pod information. +- name: Get the resource pod information. k8s_info: kind: Pod namespace: '{{ meta.namespace }}' label_selectors: - - app=awx + - "app={{ deployment_type }}" register: tower_pods until: "tower_pods['resources'][0]['status']['phase'] == 'Running'" delay: 5 retries: 60 -- name: Set the awx pod name as a variable. +- name: Set the resource pod name as a variable. set_fact: tower_pod_name: "{{ tower_pods['resources'][0]['metadata']['name'] }}" -- name: Verify tower_pod_name is populated. +- name: Verify the resource pod name is populated. assert: that: tower_pod_name != '' fail_msg: "Could not find the tower pod's name." diff --git a/roles/awx/templates/tower.yaml.j2 b/roles/awx/templates/tower.yaml.j2 index 0f46f494..8f7a4314 100644 --- a/roles/awx/templates/tower.yaml.j2 +++ b/roles/awx/templates/tower.yaml.j2 @@ -17,16 +17,16 @@ metadata: name: '{{ meta.name }}' namespace: '{{ meta.namespace }}' labels: - app: awx + app: '{{ deployment_type }}' spec: replicas: {{ tower_replicas }} selector: matchLabels: - app: awx + app: '{{ deployment_type }}' template: metadata: labels: - app: awx + app: '{{ deployment_type }}' spec: containers: - image: '{{ tower_redis_image }}' @@ -176,19 +176,19 @@ spec: path: SECRET_KEY - name: {{ meta.name }}-settings configMap: - name: '{{ meta.name }}-awx-configmap' + name: '{{ meta.name }}-{{ deployment_type }}-configmap' items: - key: settings path: settings.py - name: {{ meta.name }}-nginx-conf configMap: - name: '{{ meta.name }}-awx-configmap' + name: '{{ meta.name }}-{{ deployment_type }}-configmap' items: - key: nginx_conf path: nginx.conf - name: {{ meta.name }}-redis-config configMap: - name: {{ meta.name }}-awx-configmap + name: {{ meta.name }}-{{ deployment_type }}-configmap items: - key: redis_conf path: redis.conf @@ -217,7 +217,7 @@ metadata: name: '{{ meta.name }}-service' namespace: '{{ meta.namespace }}' labels: - app: awx + app: '{{ deployment_type }}' spec: ports: - port: 80 @@ -225,7 +225,7 @@ spec: targetPort: 8052 name: http selector: - app: awx + app: '{{ deployment_type }}' {% if tower_ingress_type != "none" %} type: NodePort {% endif %} diff --git a/roles/awx/templates/tower_config.yaml.j2 b/roles/awx/templates/tower_config.yaml.j2 index 43d8853b..4d2e23ca 100644 --- a/roles/awx/templates/tower_config.yaml.j2 +++ b/roles/awx/templates/tower_config.yaml.j2 @@ -3,10 +3,10 @@ apiVersion: v1 kind: ConfigMap metadata: - name: '{{ meta.name }}-awx-configmap' + name: '{{ meta.name }}-{{ deployment_type }}-configmap' namespace: '{{ meta.namespace }}' labels: - app: awx + app: '{{ deployment_type }}' data: environment: | DATABASE_USER=awx diff --git a/roles/awx/templates/tower_postgres.yaml.j2 b/roles/awx/templates/tower_postgres.yaml.j2 index 318f2143..824a9057 100644 --- a/roles/awx/templates/tower_postgres.yaml.j2 +++ b/roles/awx/templates/tower_postgres.yaml.j2 @@ -6,11 +6,11 @@ metadata: name: '{{ meta.name }}-postgres' namespace: '{{ meta.namespace }}' labels: - app: awx-postgres + app: '{{ deployment_type }}-postgres' spec: selector: matchLabels: - app: awx-postgres + app: '{{ deployment_type }}-postgres' serviceName: '{{ meta.name }}' replicas: 1 updateStrategy: @@ -18,7 +18,7 @@ spec: template: metadata: labels: - app: awx-postgres + app: '{{ deployment_type }}-postgres' spec: containers: - image: '{{ tower_postgres_image }}' @@ -69,11 +69,10 @@ metadata: name: '{{ meta.name }}-postgres' namespace: '{{ meta.namespace }}' labels: - app: awx-postgres + app: '{{ deployment_type }}-postgres' spec: ports: - port: 5432 clusterIP: None selector: - app: awx-postgres - + app: '{{ deployment_type }}-postgres' diff --git a/roles/awx/templates/tower_postgres_secret.yaml.j2 b/roles/awx/templates/tower_postgres_secret.yaml.j2 index cb2dc1ac..7cd8fb56 100644 --- a/roles/awx/templates/tower_postgres_secret.yaml.j2 +++ b/roles/awx/templates/tower_postgres_secret.yaml.j2 @@ -7,7 +7,7 @@ metadata: namespace: '{{ meta.namespace }}' stringData: password: '{{ lookup('password', 'p' + meta.name + 'pg length=32 chars=ascii_letters,digits') }}' - username: 'awx' - database: 'awx' + username: '{{ deployment_type }}' + database: '{{ deployment_type }}' port: '5432' host: {{ meta.name }}-postgres