Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PVC storage for containerized Ansible Tower running on OCP #590

Merged
merged 16 commits into from
Mar 17, 2021
6 changes: 6 additions & 0 deletions roles/ansible/tower/config-ansible-tower-ocp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ The variables used to install Ansible Tower on OpenShift are outlined in the tab

**Note:** As Tower Installer is based on Ansible playbooks, you may want to customize specific parts of it. You can copy over specific files by pointing to zip archive which contains new files along with the directory structure.

**Note:** Tower installer supports PostgreSQL deployment done in two way, EmptyDir and PVC based. If you choose EmptyDir (openshift_pg_emptydir=true) be aware that PostgreSQL storage is not going to be persisted in any way. If you choose PVC, and the PVC doesn't exist, this playbook will automatically create a PVC(and underlying PV) based on default configuration of you clusters PV plugin. If PVC does exist, playbook will use it.


| Variable | Description | Required | Defaults |
|:---------|:------------|:---------|:---------|
|ansible_tower_download_url|URL of Ansible Tower installer artifact repository|no|`https://releases.ansible.com/ansible-tower/setup_openshift/ansible-tower-openshift-setup-{{ ansible_tower_version }}.tar.gz`|
Expand All @@ -29,6 +32,9 @@ The variables used to install Ansible Tower on OpenShift are outlined in the tab
|openshift_skip_tls_verify| Should installer skip TLS verifcation of Openshift API|no|false|
|openshift_pg_emptydir|Flag for Postgre to use EmptyDir for storage(not recommended for Production)|no|true|
|openshift_pg_pvc_name|Persistent Volume Claim to be used for PostgreSQL storage|no|postgresql|
|openshift_pv_size|Size of PV that's going to be created for PostgreSQL storage|no|10Gi|
jfilipcz marked this conversation as resolved.
Show resolved Hide resolved
|openshift_pv_wait_retries| How many attempts should have been taken on PVC readiness check|no|5|
|openshift_pv_wait_delay| What's the delay between each attempt on making PVC readiness check (in seconds)|no|30|
|admin_user|Tower admin username|no|"admin"|
|admin_password|Tower admin user password|no|"admin"|
|admin_email|Tower admin user e-mail address|no|root@localhost|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ openshift_token: ""
openshift_skip_tls_verify: "false"
openshift_project: "tower"

# PostgreSQL should relay on PVC, but for the moment we support EmptyDir only
openshift_pg_pvc_name: "postgresql"
# Postgre can be deployed backed up by either EmptyDir or PVC, PVC will be created if openshift_pg_emptydir is set to false
openshift_pg_emptydir: "true"

# Only applicable if openshift_pg_emptydir is set to "false"
openshift_pv_size: "10Gi"
openshift_pg_pvc_name: "postgresql"

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- openshift_project

- import_tasks: openshift_retrieve_token.yml
- import_tasks: setup_pvc.yml

- name: "Download & Unpack Ansible Tower installer"
unarchive:
Expand Down Expand Up @@ -54,4 +55,3 @@
file:
state: absent
path: "{{ ansible_tower_dir }}"

52 changes: 52 additions & 0 deletions roles/ansible/tower/config-ansible-tower-ocp/tasks/setup_pvc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
- block:
- name: Ensure user is authenticated with OCP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step is already performed in the openshift_retrieve_token, so shouldn't be needed here - probably just remove this task(?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the authentication part to a separate file, but in the case that only OCP token is provided we need to have a step for login. openshift_retrieve_token was only used when username and password was provided, it did not cover the token based authentication.

shell: |
oc login {{ openshift_host }} \
--token {{ openshift_token }} \
--insecure-skip-tls-verify={{ openshift_skip_tls_verify | default(false) | bool }}
no_log: true

- name: Checking if target project exists on OCP..
command: oc get project {{ openshift_project }}
register: getProject
failed_when: false

- name: Creating target project..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be a left-over, but there's one oc get project above and two oc new-project here - seems a bit redundant + not sure what this task actually does as it registers getProject over again.

Another couple of comments:

  • Probably doesn't make sense to have the project created inside of setup_pvc as that's a bit "hidden". Better idea would be to do so in the main.yml or a separate file for creating the project
  • What happens if the project already exists, but belongs to someone else? Probably will error out at some point. Is this something we should check for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, that was overlooked and it has been fixed, I've also changed the file structure to be a bit more clean and self-explanatory. I will also look into handling the the condition in which project has already been created by other user.

shell: oc new-project {{ openshift_project }}
register: getProject
failed_when: false

- name: Creating target project..
shell: oc new-project {{ openshift_project }}
when: getProject is search("not found")

- name: Creating Temp Dir ..
file:
state: directory
path: "./temp"

- name: Source the PVC template ...
template:
src: pvc.j2
dest: "./temp/pvc.yml"

- name: Apply the PVC manifest..
shell: oc apply -f ./temp/pvc.yml
jfilipcz marked this conversation as resolved.
Show resolved Hide resolved
register: pvcoutput
failed_when: pvcoutput.rc !=0

- name: Clean the temp..
file:
state: absent
path: "./temp"

- name: Check PVC status
command: "oc get pvc {{ openshift_pg_pvc_name }} -n {{ openshift_project }} -o=jsonpath='{.status.phase}'"
register: pg_pvc_status
until: pg_pvc_status.stdout is search("Bound")
retries: "{{ openshift_pv_wait_retries | default(5) }}"
delay: "{{ openshift_pv_wait_delay | default(30) }} "

when:
- openshift_pg_emptydir|trim == 'false'
12 changes: 12 additions & 0 deletions roles/ansible/tower/config-ansible-tower-ocp/templates/pvc.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ openshift_pg_pvc_name }}
namespace: {{ openshift_project }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ openshift_pv_size}}

Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ openshift_project: "test-tower"
openshift_user: "kubeadmin"
openshift_password: "APBEh-jjrVy-hLQZX-VI9Kg"
openshift_pg_emptydir: "true"