mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 01:21:21 +03:00
a043369d07
See the OpenShift docs on this for more info: https://docs.openshift.com/container-platform/3.6/dev_guide/managing_images.html#using-is-with-k8s If you are not using OpenShift’s internal registry you will need to manually set awx_task_openshift_image and awx_web_openshift_image.
127 lines
4.5 KiB
YAML
127 lines
4.5 KiB
YAML
---
|
|
- 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: Manage AWX Container Images
|
|
block:
|
|
- name: Get docker registry password from oc if needed
|
|
block:
|
|
- name: Set docker registry password
|
|
shell: oc whoami -t
|
|
register: docker_registry_password_shell
|
|
- name: Set docker registry password
|
|
set_fact:
|
|
docker_registry_password: "{{ docker_registry_password_shell.stdout }}"
|
|
when: docker_registry_password is not defined
|
|
|
|
- name: Authenticate with Docker registry
|
|
docker_login:
|
|
registry: "{{ docker_registry }}"
|
|
username: "{{ docker_registry_username }}"
|
|
password: "{{ docker_registry_password }}"
|
|
reauthorize: yes
|
|
when: docker_registry is defined and docker_registry_password is defined
|
|
delegate_to: localhost
|
|
|
|
- name: Wait for Openshift
|
|
pause:
|
|
seconds: 30
|
|
|
|
- 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: Wait for openshift
|
|
pause:
|
|
seconds: 10
|
|
|
|
- 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: Enable image stream lookups for awx images
|
|
shell: "oc set image-lookup --all -n {{ awx_openshift_project }}"
|
|
|
|
- name: Set full web image path
|
|
set_fact:
|
|
awx_web_openshift_image: "{{ 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: "{{ awx_task_image }}:{{ awx_version }}"
|
|
when: awx_task_openshift_image is not defined
|
|
when: dockerhub_base is not defined
|
|
|
|
- name: Set DockerHub Image Paths
|
|
set_fact:
|
|
awx_web_openshift_image: "{{ dockerhub_base }}/awx_web:{{ dockerhub_version }}"
|
|
awx_task_openshift_image: "{{ dockerhub_base }}/awx_task:{{ dockerhub_version }}"
|
|
when: dockerhub_base is defined
|
|
|
|
- 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('5')}}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 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"
|