From 73a37a281d99f2d5a3e22dcee42c02e7c6cf09af Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Thu, 21 Sep 2017 21:31:26 -0400 Subject: [PATCH] Allow pre-populating the default AWX superuser account --- installer/image_build/files/launch_awx_task.sh | 9 +++++++-- installer/inventory | 5 +++++ installer/local_docker/tasks/main.yml | 6 +++++- installer/openshift/templates/deployment.yml.j2 | 4 ++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/installer/image_build/files/launch_awx_task.sh b/installer/image_build/files/launch_awx_task.sh index bc3dd24ff5..02bd0066b8 100755 --- a/installer/image_build/files/launch_awx_task.sh +++ b/installer/image_build/files/launch_awx_task.sh @@ -6,8 +6,13 @@ if [ `id -u` -ge 10000 ]; then fi ANSIBLE_REMOTE_TEMP=/tmp ANSIBLE_LOCAL_TEMP=/tmp ansible -i "127.0.0.1," -c local -v -m postgresql_db -U $DATABASE_USER -a "name=$DATABASE_NAME owner=$DATABASE_USER login_user=$DATABASE_USER login_host=$DATABASE_HOST login_password=$DATABASE_PASSWORD" all awx-manage migrate --noinput --fake-initial -echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'root@localhost', 'password')" | awx-manage shell -awx-manage create_preload_data +if [ ! -z "$AWX_ADMIN_USER" ]&&[ ! -z "$AWX_ADMIN_PASSWORD" ]; then + echo "from django.contrib.auth.models import User; User.objects.create_superuser('$AWX_ADMIN_USER', 'root@localhost', '$AWX_ADMIN_PASSWORD')" | awx-manage shell + awx-manage create_preload_data +else + echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'root@localhost', 'password')" | awx-manage shell + awx-manage create_preload_data +fi awx-manage provision_instance --hostname=$(hostname) awx-manage register_queue --queuename=tower --hostnames=$(hostname) supervisord -c /supervisor_task.conf diff --git a/installer/inventory b/installer/inventory index 6255be3664..ed458a8660 100644 --- a/installer/inventory +++ b/installer/inventory @@ -2,6 +2,11 @@ localhost ansible_connection=local ansible_python_interpreter="/usr/bin/env pyth [all:vars] +# This will create or update a default admin (superuser) account in AWX, if not provided +# then these default values are used +# default_admin_user=admin +# default_admin_password=password + # Use a local distribution build container image for building the AWX package # This is helpful if you don't want to bother installing the build-time dependencies as # it is taken care of already. diff --git a/installer/local_docker/tasks/main.yml b/installer/local_docker/tasks/main.yml index 7eba9d3575..890a8e48e7 100644 --- a/installer/local_docker/tasks/main.yml +++ b/installer/local_docker/tasks/main.yml @@ -189,6 +189,8 @@ RABBITMQ_VHOST: "awx" MEMCACHED_HOST: "memcached" MEMCACHED_PORT: "11211" + AWX_ADMIN_USER: "{{ default_admin_user|default('admin') }}" + AWX_ADMIN_PASSWORD: "{{ default_admin_password|default('password') }}" - name: Activate AWX Task Container docker_container: @@ -212,4 +214,6 @@ RABBITMQ_VHOST: "awx" MEMCACHED_HOST: "memcached" MEMCACHED_PORT: "11211" - SECRET_KEY: "{{ awx_secret_key }}" + AWX_ADMIN_USER: "{{ default_admin_user|default('admin') }}" + AWX_ADMIN_PASSWORD: "{{ default_admin_password|default('password') }}" + diff --git a/installer/openshift/templates/deployment.yml.j2 b/installer/openshift/templates/deployment.yml.j2 index 5b8d11fd1f..783b9c422a 100644 --- a/installer/openshift/templates/deployment.yml.j2 +++ b/installer/openshift/templates/deployment.yml.j2 @@ -34,6 +34,10 @@ spec: value: {{ pg_hostname|default('postgresql') }} - name: DATABASE_PASSWORD value: {{ pg_password }} + - name: AWX_ADMIN_USER + value: {{ default_admin_user|default('admin') }} + - name: AWX_ADMIN_PASSWORD + value: {{ default_admin_password|default('password') }} - name: awx-rabbit image: rabbitmq:3 env: