Initial awx installer

This commit is contained in:
Matthew Jones
2017-08-15 21:42:18 -04:00
committed by Matthew Jones
parent de2aa2792a
commit d39c70d9f2
16 changed files with 312 additions and 57 deletions

View File

@@ -1,54 +0,0 @@
FROM centos:7
# Do we need this?
#RUN locale-gen en_US.UTF-8
#ENV LANG en_US.UTF-8
#ENV LANGUAGE en_US:en
#ENV LC_ALL en_US.UTF-8
USER root
# Init System
ADD https://github.com/krallin/tini/releases/download/v0.14.0/tini /tini
RUN chmod +x /tini
ADD Makefile /tmp/Makefile
RUN mkdir /tmp/requirements
ADD requirements/requirements_ansible.txt \
requirements/requirements_ansible_uninstall.txt \
requirements/requirements_ansible_git.txt \
requirements/requirements.txt \
requirements/requirements_tower_uninstall.txt \
requirements/requirements_git.txt \
/tmp/requirements/
# OS Dependencies
RUN yum -y install epel-release && yum -y localinstall http://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm && yum -y update && yum -y install ansible git curl python-psycopg2 python-pip python-setuptools libselinux-python setools-libs yum-utils sudo acl make postgresql-devel nginx python-psutil libxml2-devel libxslt-devel libstdc++.so.6 gcc cyrus-sasl-devel cyrus-sasl openldap-devel libffi-devel python-pip xmlsec1-devel swig krb5-devel xmlsec1-openssl xmlsec1 xmlsec1-openssl-devel libtool-ltdl-devel bubblewrap gcc-c++ python-devel
RUN pip install virtualenv supervisor
WORKDIR /tmp
RUN mkdir -p /var/lib/awx/public/static
RUN mkdir -p /var/log/tower
RUN mkdir -p /etc/tower
RUN echo "awxsecret" > /etc/tower/SECRET_KEY
RUN VENV_BASE=/var/lib/awx/venv make requirements_ansible && VENV_BASE=/var/lib/awx/venv make requirements_awx
COPY dist/awx-{{ version }}.tar.gz /tmp/awx-{{ version }}.tar.gz
RUN OFFICIAL=yes pip install /tmp/awx-{{ version }}.tar.gz
RUN echo "{{ version }}" > /var/lib/awx/.tower_version
ADD installer/openshift/nginx.conf /etc/nginx/nginx.conf
ADD installer/openshift/supervisor.conf /supervisor.conf
ADD installer/openshift/supervisor_task.conf /supervisor_task.conf
ADD installer/openshift/launch_awx.sh /usr/bin/launch_awx.sh
ADD installer/openshift/launch_awx_task.sh /usr/bin/launch_awx_task.sh
ADD installer/openshift/settings.py /etc/tower/settings.py
RUN yum -y remove gcc postgresql-devel libxml2-devel libxslt-devel cyrus-sasl-devel openldap-devel xmlsec1-devel krb5-devel xmlsec1-openssl-devel libtool-ltdl-devel gcc-c++ python-devel && yum -y clean all
RUN rm -rf /root/.cache
RUN chmod g+w /etc/passwd
RUN chgrp -Rf root /var/lib/awx && chmod -Rf g+w /var/lib/awx
RUN chmod -R 777 /var/log/nginx && chmod -R 777 /var/lib/nginx
USER 1000
EXPOSE 8052
WORKDIR /var/lib/awx
ENTRYPOINT ["/tini", "--"]
CMD /usr/bin/launch_awx.sh

View File

@@ -1,6 +0,0 @@
FROM awx_web
USER 0
RUN sudo yum -y remove nginx
USER 1000
EXPOSE 8052
CMD /usr/bin/launch_awx_task.sh

View File

@@ -1,5 +0,0 @@
[primary]
localhost
[all:children]
primary

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env bash
if [ `id -u` -ge 10000 ]; then
echo "awx:x:`id -u`:`id -g`:,,,:/var/lib/awx:/bin/bash" >> /tmp/passwd
cat /tmp/passwd > /etc/passwd
rm /tmp/passwd
fi
awx-manage collectstatic --noinput --clear
supervisord -c /supervisor.conf

View File

@@ -1,13 +0,0 @@
#!/usr/bin/env bash
if [ `id -u` -ge 10000 ]; then
echo "awx:x:`id -u`:`id -g`:,,,:/var/lib/awx:/bin/bash" >> /tmp/passwd
cat /tmp/passwd > /etc/passwd
rm /tmp/passwd
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
awx-manage provision_instance --hostname=$(hostname)
awx-manage register_queue --queuename=tower --hostnames=$(hostname)
supervisord -c /supervisor_task.conf

View File

@@ -1,86 +0,0 @@
user awx;
worker_processes 1;
error_log /dev/stdout warn;
pid /tmp/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/stdout main;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
sendfile on;
#tcp_nopush on;
#gzip on;
upstream uwsgi {
server localhost:8050;
}
upstream daphne {
server localhost:8051;
}
server {
listen 8052 default_server;
# If you have a domain name, this is where to add it
server_name _;
keepalive_timeout 65;
# HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
add_header Strict-Transport-Security max-age=15768000;
location /static/ {
alias /var/lib/awx/public/static/;
}
location /favicon.ico { alias /var/lib/awx/public/static/favicon.ico; }
location /websocket {
# Pass request to the upstream alias
proxy_pass http://daphne;
# Require http version 1.1 to allow for upgrade requests
proxy_http_version 1.1;
# We want proxy_buffering off for proxying to websockets.
proxy_buffering off;
# http://en.wikipedia.org/wiki/X-Forwarded-For
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# enable this if you use HTTPS:
proxy_set_header X-Forwarded-Proto https;
# pass the Host: header from the client for the sake of redirects
proxy_set_header Host $http_host;
# We've set the Host header, so we don't need Nginx to muddle
# about with redirects
proxy_redirect off;
# Depending on the request value, set the Upgrade and
# connection headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
location / {
# Add trailing / if missing
rewrite ^(.*[^/])$ $1/ permanent;
uwsgi_read_timeout 120s;
uwsgi_pass uwsgi;
include /etc/nginx/uwsgi_params;
}
}
}

View File

@@ -1,80 +0,0 @@
# AWX settings file
import os
ADMINS = ()
STATIC_ROOT = '/var/lib/awx/public/static'
PROJECTS_ROOT = '/var/lib/awx/projects'
JOBOUTPUT_ROOT = '/var/lib/awx/job_status'
SECRET_KEY = file('/etc/tower/SECRET_KEY', 'rb').read().strip()
ALLOWED_HOSTS = ['*']
INTERNAL_API_URL = 'http://127.0.0.1:80'
AWX_TASK_ENV['HOME'] = '/var/lib/awx'
###############################################################################
# EMAIL SETTINGS
###############################################################################
SERVER_EMAIL = 'root@localhost'
DEFAULT_FROM_EMAIL = 'webmaster@localhost'
EMAIL_SUBJECT_PREFIX = '[AWX] '
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
LOGGING['loggers']['django.request']['handlers'] = ['console']
LOGGING['loggers']['rest_framework.request']['handlers'] = ['console']
LOGGING['loggers']['awx']['handlers'] = ['console']
LOGGING['loggers']['awx.main.commands.run_callback_receiver']['handlers'] = ['console']
LOGGING['loggers']['awx.main.commands.inventory_import']['handlers'] = ['console']
LOGGING['loggers']['awx.main.tasks']['handlers'] = ['console']
LOGGING['loggers']['awx.main.scheduler']['handlers'] = ['console']
LOGGING['loggers']['awx.main.commands.run_fact_cache_receiver']['handlers'] = ['console']
LOGGING['loggers']['django_auth_ldap']['handlers'] = ['console']
LOGGING['loggers']['social']['handlers'] = ['console']
LOGGING['loggers']['system_tracking_migrations']['handlers'] = ['console']
LOGGING['loggers']['rbac_migrations']['handlers'] = ['console']
DATABASES = {
'default': {
'ATOMIC_REQUESTS': True,
'ENGINE': 'transaction_hooks.backends.postgresql_psycopg2',
'NAME': os.getenv("DATABASE_NAME", None),
'USER': os.getenv("DATABASE_USER", None),
'PASSWORD': os.getenv("DATABASE_PASSWORD", None),
'HOST': os.getenv("DATABASE_HOST", None),
'PORT': os.getenv("DATABASE_PORT", None),
}
}
BROKER_URL = 'amqp://{}:{}@{}:{}/{}'.format(
os.getenv("RABBITMQ_USER", None),
os.getenv("RABBITMQ_PASSWORD", None),
os.getenv("RABBITMQ_HOST", None),
os.getenv("RABBITMQ_PORT", "5672"),
os.getenv("RABBITMQ_VHOST", "tower"))
CHANNEL_LAYERS = {
'default': {'BACKEND': 'asgi_amqp.AMQPChannelLayer',
'ROUTING': 'awx.main.routing.channel_routing',
'CONFIG': {'url': BROKER_URL}}
}
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '{}:{}'.format(os.getenv("MEMCACHED_HOST", None),
os.getenv("MEMCACHED_PORT", "11211"))
},
}

View File

@@ -1,51 +0,0 @@
[supervisord]
nodaemon = True
umask = 022
[program:nginx]
command = nginx -g "daemon off;"
autostart = true
autorestart = true
stopwaitsecs = 5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:uwsgi]
command = /var/lib/awx/venv/awx/bin/uwsgi --socket 127.0.0.1:8050 --module=awx.wsgi:application --vacuum --processes=5 --harakiri=120 --no-orphans --master --max-requests=1000 --master-fifo=/var/lib/awx/awxfifo --lazy-apps -b 32768
directory = /var/lib/awx
autostart = true
2autorestart = true
stopwaitsecs = 15
stopsignal = INT
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:daphne]
command = /var/lib/awx/venv/awx/bin/daphne -b 127.0.0.1 -p 8051 awx.asgi:channel_layer
directory = /var/lib/awx
autostart = true
autorestart = true
stopwaitsecs = 5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[group:tower-processes]
programs=nginx,uwsgi,daphne
priority=5
# TODO: Exit Handler
[unix_http_server]
file=/tmp/supervisor.sock
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

View File

@@ -1,66 +0,0 @@
[supervisord]
nodaemon = True
umask = 022
[program:celery]
# TODO: Needs to be reworked to dynamically use instance group queues
command = awx-manage celery worker -l debug --autoscale=4 -Ofair -Q tower_scheduler,tower_broadcast_all,tower,%(host_node_name)s -n celery@localhost
directory = /var/lib/awx
environment = LANGUAGE="en_US.UTF-8",LANG="en_US.UTF-8",LC_ALL="en_US.UTF-8",LC_CTYPE="en_US.UTF-8"
#user = {{ aw_user }}
autostart = true
autorestart = true
stopwaitsecs = 5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:awx-celeryd-beat]
command = /usr/bin/awx-manage celery beat -l debug --pidfile= -s /var/lib/awx/beat.db
directory = /var/lib/awx
autostart = true
autorestart = true
stopwaitsecs = 5
redirect_stderr=true
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0
[program:callback-receiver]
command = awx-manage run_callback_receiver
directory = /var/lib/awx
autostart = true
autorestart = true
stopwaitsecs = 5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:channels-worker]
command = awx-manage runworker --only-channels websocket.*
directory = /var/lib/awx
autostart = true
autorestart = true
stopwaitsecs = 5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[group:tower-processes]
programs=celery,callback-receiver,channels-worker
priority=5
# TODO: Exit Handler
[unix_http_server]
file=/tmp/supervisor.sock
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

View File

@@ -0,0 +1,95 @@
---
- name: Authenticate with OpenShift
shell: "oc login {{ openshift_host }} -u {{ openshift_user }} -p {{ openshift_password }}"
- name: Get Project Detail
shell: "oc get project {{ awx_openshift_project }}"
register: project_details
ignore_errors: yes
- name: Get Postgres Service Detail
shell: "oc describe svc postgresql -n {{ awx_openshift_project }}"
register: postgres_svc_details
ignore_errors: yes
when: "pg_hostname is not defined or pg_hostname == ''"
- name: Create AWX Openshift Project
shell: "oc new-project {{ awx_openshift_project }}"
when: project_details.rc != 0
# This might could/should be optional based on certain circumstances
- name: Mark Openshift User as Admin
shell: "oc adm policy add-role-to-user admin {{ openshift_user }} -n {{ awx_openshift_project }}"
- name: Authenticate with Docker registry
docker_login:
registry: "{{ docker_registry }}"
username: "{{ docker_registry_username }}"
password: "{{ docker_registry_password }}"
when: docker_registry is defined
delegate_to: localhost
- name: Tag and push web image to registry
docker_image:
name: "{{ awx_web_image }}"
repository: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_web_image }}"
tag: "{{ awx_version }}"
push: yes
when: docker_registry is defined
delegate_to: localhost
- name: Tag and push task image to registry
docker_image:
name: "{{ awx_task_image }}"
repository: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_task_image }}"
tag: "{{ awx_version }}"
push: yes
when: docker_registry is defined
delegate_to: localhost
- name: Deploy and Activate Postgres
shell: "oc new-app --template=postgresql-persistent -e MEMORY_LIMIT={{ pg_memory_limit|default('512') }}Mi -e NAMESPACE=openshift -e DATABASE_SERVICE_NAME=postgresql -e POSTGRESQL_USER={{ pg_username }} -e POSTGRESQL_PASSWORD={{ pg_password }} -e POSTGRESQL_DATABASE={{ pg_database }} -e VOLUME_CAPACITY={{ pg_volume_capacity|default('1')}}Gi -e POSTGRESQL_VERSION=9.5 -n {{ awx_openshift_project }}"
when: (pg_hostname is not defined or pg_hostname == '') and (postgres_svc_details is defined and postgres_svc_details.rc != 0)
register: openshift_pg_activate
- name: Wait for Postgres to activate
pause:
seconds: 15
when: openshift_pg_activate|changed
- name: Set full web image path
set_fact:
awx_web_openshift_image: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_web_image }}:{{ awx_version }}"
when: awx_web_openshift_image is not defined
- name: Set full task image path
set_fact:
awx_task_openshift_image: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_task_image }}:{{ awx_version }}"
when: awx_task_openshift_image is not defined
- name: Set openshift base path
set_fact:
openshift_base_path: "{{ awx_local_base_config_path|default('/tmp') }}/awx-config"
- name: Ensure directory exists
file:
path: "{{ openshift_base_path }}"
state: directory
- name: Template Openshift AWX Config
template:
src: configmap.yml.j2
dest: "{{ openshift_base_path }}/configmap.yml"
mode: '0600'
- name: Template Openshift AWX Deployment
template:
src: deployment.yml.j2
dest: "{{ openshift_base_path }}/deployment.yml"
mode: '0600'
- name: Apply Configmap
shell: "oc apply -f {{ openshift_base_path }}/configmap.yml"
- name: Apply Deployment
shell: "oc apply -f {{ openshift_base_path }}/deployment.yml"

View File

@@ -1,11 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: tower-config
namespace: tower
name: awx-config
namespace: {{ awx_openshift_project }}
data:
secret_key: AAABBBCCC
tower_settings: |
secret_key: {{ awx_secret_key }}
awx_settings: |
import os
import socket
ADMINS = ()
@@ -59,19 +59,19 @@ data:
'default': {
'ATOMIC_REQUESTS': True,
'ENGINE': 'transaction_hooks.backends.postgresql_psycopg2',
'NAME': "tower",
'USER': "tower",
'PASSWORD': "password123",
'HOST': "postgresql",
'PORT': "5432",
'NAME': "{{ pg_database }}",
'USER': "{{ pg_username }}",
'PASSWORD': "{{ pg_password }}",
'HOST': "{{ pg_hostname|default('postgresql') }}",
'PORT': "{{ pg_port }}",
}
}
BROKER_URL = 'amqp://{}:{}@{}:{}/{}'.format(
"tower",
"awx",
"abcdefg",
"localhost",
"5672",
"tower")
"awx")
CHANNEL_LAYERS = {
'default': {'BACKEND': 'asgi_amqp.AMQPChannelLayer',
'ROUTING': 'awx.main.routing.channel_routing',

View File

@@ -2,59 +2,59 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: tower
namespace: tower
name: awx
namespace: {{ awx_openshift_project }}
spec:
replicas: 1
template:
metadata:
labels:
name: tower-web-deploy
name: awx-web-deploy
service: django
spec:
containers:
- name: tower-web
image: 172.30.1.1:5000/tower/tower_web:latest
- name: awx-web
image: {{ awx_web_openshift_image }}
ports:
- containerPort: 8052
volumeMounts:
- mountPath: /etc/tower
name: tower-application-config
- name: tower-celery
image: 172.30.1.1:5000/tower/tower_task:latest
name: awx-application-config
- name: awx-celery
image: {{ awx_task_openshift_image }}
volumeMounts:
- mountPath: /etc/tower
name: tower-application-config
name: awx-application-config
env:
- name: DATABASE_USER
value: tower
value: {{ pg_username }}
- name: DATABASE_NAME
value: tower
value: {{ pg_database }}
- name: DATABASE_HOST
value: postgresql
value: {{ pg_hostname|default('postgresql') }}
- name: DATABASE_PASSWORD
value: password123
- name: tower-rabbit
value: {{ pg_password }}
- name: awx-rabbit
image: rabbitmq:3
env:
- name: RABBITMQ_ERLANG_COOKIE
value: secret
value: secretb
- name: RABBITMQ_NODENAME
value: rabbitmq
- name: RABBITMQ_DEFAULT_USER
value: tower
value: awx
- name: RABBITMQ_DEFAULT_PASS
value: abcdefg
- name: RABBITMQ_DEFAULT_VHOST
value: tower
- name: tower-memcached
value: awx
- name: awx-memcached
image: memcached
volumes:
- name: tower-application-config
- name: awx-application-config
configMap:
name: tower-config
name: awx-config
items:
- key: tower_settings
- key: awx_settings
path: settings.py
- key: secret_key
path: SECRET_KEY
@@ -62,15 +62,15 @@ spec:
apiVersion: v1
kind: Service
metadata:
name: tower-web-svc
namespace: tower
name: awx-web-svc
namespace: {{ awx_openshift_project }}
labels:
name: tower-web-svc
name: awx-web-svc
spec:
type: "NodePort"
ports:
- name: http
port: 8052
nodePort: 30083
nodePort: {{ awx_node_port }}
selector:
name: tower-web-deploy
name: awx-web-deploy

View File

@@ -1,5 +0,0 @@
admin_password: password
database: internal
pg_password: CJUWsyKHp5P9AZZqC8Rgk7qFnVVFAPBCJbkzr3bb
primary_machine: localhost
redis_password: xrQ5uWpfH8ELWyKzfkS8UCRVAjaFruKQq3EvR4a6