-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add adhoc playbook to create pv for openshift namespace
Signed-off-by: siddharthvipul <[email protected]>
- Loading branch information
1 parent
6b26da1
commit 72a119f
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}" | ||
} | ||
} | ||
} |