-
Notifications
You must be signed in to change notification settings - Fork 20
/
adhoc-ocp-deploy-jenkins-for-ci-tenant.yml
155 lines (137 loc) · 4.04 KB
/
adhoc-ocp-deploy-jenkins-for-ci-tenant.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
# 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:
- ci-rdu2
- ci-aws
- ci-aws-stg
private: False
vars:
ocp_groups:
ci-rdu2: ocp-ci-management
ci-aws-stg: ocp-stg-ci-management
ci-aws: aws-ocp-ci-management
tasks:
- set_fact:
mgmt_hosts: "{{ ocp_groups[ocp_env] }}"
tags:
- vars
- add_host:
name: "{{ item }}"
groups: ocp_target_host
with_items: "{{ groups[mgmt_hosts] }}"
tags:
- vars
- hosts: ocp_target_host
become: true
become_user: "{{ ocp_service_account }}"
vars_prompt:
- name: "ocp_project"
prompt: "Existing project/namespace in ocp we'll deploy jenkins to/for (has to exist before !) "
private: no
- name: "pv_size"
prompt: "Persistent Volume size (example 10Gi) "
private: no
- name: "duffy_api_key"
prompt: "Existing Duffy API key "
private: no
#- name: "duffy_ssh_key"
# prompt: "Existing ssh private key this project to be injected as secret "
vars:
pv_claimref: jenkins
pv_name: jenkins
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: 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
- name: Finding project ssh key to inject as secret
set_fact:
duffy_ssh_key: "{{ lookup('file', '{{ pkistore }}/ocp/ssh/{{ ocp_project }}') }}"
tags:
- template
- name: Importing basic jenkins-ci-workspace template
template:
src: openshift/jenkins-ci-workspace.yml
dest: "/home/{{ ocp_service_account }}/ocp_configs/{{ ocp_project }}-jenkins-ci-workspace.yml"
tags:
- template
- name: "Deploy jenkins under namespace {{ ocp_project }}"
shell:
cmd: "bin/oc process -f ocp_configs/{{ ocp_project }}-jenkins-ci-workspace.yml | bin/oc create -n {{ ocp_project }} -f -"
chdir: "/home/{{ ocp_service_account }}"
tags:
- deploy