Skip to content

Commit

Permalink
add adhoc playbook to create pv for openshift namespace
Browse files Browse the repository at this point in the history
Signed-off-by: siddharthvipul <[email protected]>
  • Loading branch information
siddharthvipul committed Jun 3, 2020
1 parent 6b26da1 commit 72a119f
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
71 changes: 71 additions & 0 deletions adhoc-openshift-pv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
# This playbook is to create a persistent volume for openshift CI namespace
# Example to run the playbook
# `ansible-playbook -e "env_prefix=ocp-prod" -e "pv_size=10Gi" -e
# "cico_project_name=new_fancy_project" adhoc-openshift-pv.yml -i inventory`


- hosts: "{{ ocp_management_group }}"
become: true
become_user: "{{ ocp_service_account }}"
vars:
ocp_management_group:
- "{{ ocp_ci_management }}"

tasks:
- name: Generate a UUID
set_fact:
pv_uuid: "{{ (cico_project_name + pv_claimref|default('noclaimref', true)) | to_uuid }}"
tags:
- pv

- name: UUID Generated
debug:
var: pv_uuid
tags:
- pv

- name: Make a pv name
set_fact:
pv_name: "pv-{{ pv_size | lower }}-{{ pv_uuid }}"
tags:
- pv

- name: UUID Generated
debug:
var: pv_name
tags:
- pv

- name: See if the PV already exists
command: "/home/{{ ocp_service_account }}/bin/oc get pv/{{ pv_name }}"
register: results
changed_when: false
failed_when:
- results.rc == 0
tags:
- pv

- name: make directories for each PV
file:
path: "/exports/{{ env_prefix }}/{{ pv_name }}"
owner: nfsnobody
group: nfsnobody
mode: 0777
state: directory
delegate_to: {{ storage_server }}
tags:
- pv

- name: create json files for PV
template:
src: "templates/openshift-pv-storage/persistent-volume.json.j2"
dest: "/home/{{ ocp_service_account }}/{{ pv_name }}.json"
tags:
- pv

- name: apply the transformation
command: "/home/{{ ocp_service_account }}/bin/oc create -f /home/{{ ocp_service_account }}/{{ pv_name }}.json"
tags:
- pv

28 changes: 28 additions & 0 deletions templates/openshift-pv-storage/persistent-volume.json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

{
"apiVersion": "v1",
"kind": "PersistentVolume",
"metadata": {
"name": "{{ pv_name }}",
"labels": {
"type": "nfs"
}
},
"spec": {
"capacity": {
"storage": "{{ pv_size }}"
},
"accessModes": [ "ReadWriteOnce", "ReadOnlyMany", "ReadWriteMany" ],
"persistentVolumeReclaimPolicy": "Retain",
{% if pv_claimref is defined %}
"claimref": {
"name": "{{ pv_claimref }}",
"namespace": "{{ cico_project_name }}"
},
{% endif %}
"nfs": {
"server": "{{ storage_server }}",
"path": "/exports/{{ env_prefix }}/{{ pv_name }}"
}
}
}

0 comments on commit 72a119f

Please sign in to comment.