mirror of
https://github.com/ansible/awx-operator.git
synced 2026-05-08 14:22:49 +00:00
Use k8s-exec instead of shell
This commit is contained in:
committed by
Shane McDonald
parent
aa579cf61f
commit
8b681313bc
@@ -1,8 +1,5 @@
|
|||||||
FROM quay.io/operator-framework/ansible-operator:v0.17.0
|
FROM quay.io/operator-framework/ansible-operator:v0.17.0
|
||||||
|
|
||||||
# Install kubectl.
|
|
||||||
COPY --from=lachlanevenson/k8s-kubectl:v1.18.3 /usr/local/bin/kubectl /usr/local/bin/kubectl
|
|
||||||
|
|
||||||
# Install Ansible requirements.
|
# Install Ansible requirements.
|
||||||
COPY requirements.yml ${HOME}/requirements.yml
|
COPY requirements.yml ${HOME}/requirements.yml
|
||||||
RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \
|
RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \
|
||||||
|
|||||||
@@ -26,3 +26,6 @@ galaxy_info:
|
|||||||
- deployment
|
- deployment
|
||||||
|
|
||||||
dependencies: []
|
dependencies: []
|
||||||
|
|
||||||
|
collections:
|
||||||
|
- community.kubernetes
|
||||||
|
|||||||
@@ -1,28 +1,37 @@
|
|||||||
---
|
---
|
||||||
- name: Check if there are any AWX super users defined.
|
- name: Check if there are any super users defined.
|
||||||
shell: >-
|
k8s_exec:
|
||||||
kubectl exec -n {{ meta.namespace }} -c {{ meta.name }}-task {{ tower_pod_name }} -- bash -c
|
namespace: "{{ meta.namespace }}"
|
||||||
"echo 'from django.contrib.auth.models import User;
|
pod: "{{ tower_pod_name }}"
|
||||||
nsu = User.objects.filter(is_superuser=True).count();
|
container: "{{ meta.name }}-task"
|
||||||
exit(0 if nsu > 0 else 1)'
|
command: >-
|
||||||
| awx-manage shell"
|
bash -c "echo 'from django.contrib.auth.models import User;
|
||||||
|
nsu = User.objects.filter(is_superuser=True).count();
|
||||||
|
exit(0 if nsu > 0 else 1)'
|
||||||
|
| awx-manage shell"
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: users_result
|
register: users_result
|
||||||
changed_when: users_result.rc > 0
|
changed_when: users_result.return_code > 0
|
||||||
|
|
||||||
- name: Create AWX super user via Django if it doesn't exist.
|
- name: Create super user via Django if it doesn't exist.
|
||||||
shell: >-
|
k8s_exec:
|
||||||
kubectl exec -n {{ meta.namespace }} -c {{ meta.name }}-task {{ tower_pod_name }} -- bash -c
|
namespace: "{{ meta.namespace }}"
|
||||||
"echo \"from django.contrib.auth.models import User;
|
pod: "{{ tower_pod_name }}"
|
||||||
User.objects.create_superuser('{{ tower_admin_user }}', '{{ tower_admin_email }}', '{{ tower_admin_password }}')\"
|
container: "{{ meta.name }}-task"
|
||||||
| awx-manage shell"
|
command: >-
|
||||||
when: users_result.rc > 0
|
bash -c "echo \"from django.contrib.auth.models import User;
|
||||||
|
User.objects.create_superuser('{{ tower_admin_user }}', '{{ tower_admin_email }}', '{{ tower_admin_password }}')\"
|
||||||
|
| awx-manage shell"
|
||||||
|
when: users_result.return_code > 0
|
||||||
no_log: true
|
no_log: true
|
||||||
|
|
||||||
- name: Create preload data if necessary. # noqa 305
|
- name: Create preload data if necessary. # noqa 305
|
||||||
shell: >-
|
k8s_exec:
|
||||||
kubectl exec -n {{ meta.namespace }} -c {{ meta.name }}-task {{ tower_pod_name }} -- bash -c
|
namespace: "{{ meta.namespace }}"
|
||||||
"awx-manage create_preload_data"
|
pod: "{{ tower_pod_name }}"
|
||||||
|
container: "{{ meta.name }}-task"
|
||||||
|
command: >-
|
||||||
|
bash -c "awx-manage create_preload_data"
|
||||||
register: cdo
|
register: cdo
|
||||||
changed_when: "'added' in cdo.stdout"
|
changed_when: "'added' in cdo.stdout"
|
||||||
when: tower_create_preload_data | bool
|
when: tower_create_preload_data | bool
|
||||||
|
|||||||
@@ -89,22 +89,28 @@
|
|||||||
fail_msg: "Could not find the tower pod's name."
|
fail_msg: "Could not find the tower pod's name."
|
||||||
|
|
||||||
- name: Check if database is populated (auth_user table exists).
|
- name: Check if database is populated (auth_user table exists).
|
||||||
shell: >-
|
k8s_exec:
|
||||||
kubectl exec -n {{ meta.namespace }} -c {{ meta.name }}-task {{ tower_pod_name }} -- bash -c
|
namespace: "{{ meta.namespace }}"
|
||||||
"echo 'from django.db import connection;
|
pod: "{{ tower_pod_name }}"
|
||||||
tbl = \"auth_user\" in connection.introspection.table_names();
|
container: "{{ meta.name }}-task"
|
||||||
exit(0 if tbl else 1)'
|
command: >-
|
||||||
| awx-manage shell"
|
bash -c "echo 'from django.db import connection;
|
||||||
|
tbl = \"auth_user\" in connection.introspection.table_names();
|
||||||
|
exit(0 if tbl else 1)'
|
||||||
|
| awx-manage shell"
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
changed_when: false
|
changed_when: false
|
||||||
register: database_check
|
register: database_check
|
||||||
when: k8s_defs_result is not changed
|
when: k8s_defs_result is not changed
|
||||||
|
|
||||||
- name: Migrate the database if the K8s resources were updated. # noqa 305
|
- name: Migrate the database if the K8s resources were updated. # noqa 305
|
||||||
shell: >-
|
k8s_exec:
|
||||||
kubectl exec -n {{ meta.namespace }} -c {{ meta.name }}-task {{ tower_pod_name }} -- bash -c
|
namespace: "{{ meta.namespace }}"
|
||||||
"awx-manage migrate --noinput"
|
pod: "{{ tower_pod_name }}"
|
||||||
|
container: "{{ meta.name }}-task"
|
||||||
|
command: >-
|
||||||
|
bash -c "awx-manage migrate --noinput"
|
||||||
register: migrate_result
|
register: migrate_result
|
||||||
when: (k8s_defs_result is changed) or (database_check is defined and database_check.rc != 0)
|
when: (k8s_defs_result is changed) or (database_check is defined and database_check.return_code != 0)
|
||||||
|
|
||||||
- include_tasks: initialize.yml
|
- include_tasks: initialize.yml
|
||||||
|
|||||||
Reference in New Issue
Block a user