-
Notifications
You must be signed in to change notification settings - Fork 20
/
adhoc-openshift-pv.yml
93 lines (80 loc) · 2.47 KB
/
adhoc-openshift-pv.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
# This playbook is to create a persistent volume for openshift CI namespace
# Needed variables as extra-vars:
# - pv_size (like 100Gi)
# - cico_project_name (registry)
# - host (where to execute command, like ocp-admin.ci.centos.org)
# Example to run the playbook
# ansible-playbook-ci playbooks/adhoc-openshift-pv.yml -e "host=n4-136.cloud.ci.centos.org" -e "pv_size=10Gi" -e "cico_project_name=test"
# The node on which we'll run this should have the exported NFS volume mounted locally
# using variables from inventory:
# ocp_nfs_server: (like node.domain)
# ocp_nfs_export: ocp-staging
- hosts: "{{ host }}"
become: true
become_user: "{{ ocp_service_account }}"
tasks:
- name: Generate a UUID
set_fact:
pv_uuid: "{{ (cico_project_name + pv_claimref|default('noclaimref', true)) | to_uuid }}"
tags:
- pv
- nfs
- name: UUID Generated
debug:
var: pv_uuid
tags:
- pv
- nfs
- name: Make a pv name
set_fact:
pv_name: "pv-{{ pv_size | lower }}-{{ pv_uuid }}"
tags:
- pv
- nfs
- name: UUID Generated
debug:
var: pv_name
tags:
- pv
- nfs
- 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
- block:
- name: Ensuring we have local mount point
file:
path: /mnt/ocp_store
state: directory
- name: Ensuring nfs export is mounted on mgmt station
mount:
fstype: nfs
src: "{{ ocp_nfs_server }}:{{ ocp_nfs_export }}"
path: /mnt/ocp_store
state: mounted
- name: make directories for each PV
file:
path: "/mnt/ocp_store/{{ pv_name }}"
owner: nobody
group: nobody
mode: 0777
state: directory
become_user: root
tags:
- pv
- nfs
- 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