-
Notifications
You must be signed in to change notification settings - Fork 20
/
adhoc-ocp-create-pv.yml
137 lines (118 loc) · 3.32 KB
/
adhoc-ocp-create-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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
# This playbook is to create a persistent volume for openshift CI namespace
# 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: localhost
vars_prompt:
- name: "ocp_env"
prompt: |
Select OCP env:
- stream-rdu2
- ci-aws
- ci-aws-stg
private: False
vars:
ocp_groups:
stream-rdu2: ocp-admin-nodes
ci-aws-stg: ocp-stg-ci-management
ci-aws: aws-ocp-ci-management
tasks:
- set_fact:
mgmt_hosts: "{{ ocp_groups[ocp_env] }}"
- add_host:
name: "{{ item }}"
groups: ocp_target_host
with_items: "{{ groups[mgmt_hosts] }}"
- hosts: ocp_target_host
become: true
become_user: "{{ ocp_service_account }}"
vars_prompt:
- name: "ocp_project"
prompt: "Existing project for which we'll just create a PV "
private: no
- name: "pv_name"
prompt: "Reason for PV (computed into uuid) "
private: no
- name: "pv_claimref"
prompt: "PV Reference Name for the Claim "
private: no
- name: "pv_size"
prompt: "Persistent Volume size (example 10Gi) "
private: no
tasks:
- name: Generate a UUID
set_fact:
pv_uuid: "{{ (ocp_project + '-' + pv_claimref|default('noclaimref', true)) + '-' + pv_name | 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:
cmd: "bin/oc get pv/{{ pv_name }}"
chdir: "/home/{{ ocp_service_account }}"
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: Ensuring we can store pv config files to apply
file:
path: "/home/{{ ocp_service_account }}/pv_configs/"
state: directory
- name: create json files for PV
template:
src: "templates/openshift-pv-storage/pv.yml.j2"
dest: "/home/{{ ocp_service_account }}/pv_configs/{{ pv_name }}.yml"
register: pv_init
tags:
- pv
- name: apply the transformation
command:
cmd: "bin/oc create -f pv_configs/{{ pv_name }}.yml"
chdir: "/home/{{ ocp_service_account }}"
when: pv_init is changed
tags:
- pv