Pablo Navascues Jimenez
2019-09-09 6fd6b979a60a0b59af591b53a66c35a99d388eda
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#############################################
# Deployment of Lab Instructions in cluster #
#############################################
 
- name: Import workshopper image
  shell: >
    oc import-image quay.io/osevg/workshopper -n openshift --confirm
 
- name: Check if project exists
  k8s_facts:
    api_version: apps.openshift.io/v1
    kind: Project
    name: "{{labguide_project_name}}"
  register: project_exists
 
- name: Create {{labguide_project_name}} project
  k8s:
    state: present
    definition:
      apiVersion: project.openshift.io/v1
      kind: Project
      metadata:
        name: "{{labguide_project_name}}"
  when:
    - project_exists.resources | list | length < 1
 
- name: check if guide is deployed
  k8s_facts:
    api_version: apps.openshift.io/v1
    kind: DeploymentConfig
    name: "{{ _deployed_guide_name }}"
    namespace: "{{labguide_project_name}}"
  register: guide_exists
 
- name: Workshop guide deployment
  shell: >
    oc new-app -n {{labguide_project_name}} --name {{ _deployed_guide_name }} --image-stream=workshopper
    -e API_URL={{api_url}}
    -e MASTER_URL={{console_url}}
    -e ROUTE_SUBDOMAIN={{ apps_base_domain }}
    -e CONTENT_URL_PREFIX={{_deployed_guide_string_url}}
    -e WORKSHOPS_URLS={{_deployed_guide_string_url}}/_index.yml
  when:
    - guide_exists.resources | list | length < 1
 
- name: lab guide route
  k8s:
    state: present
    definition:
      apiVersion: route.openshift.io/v1
      kind: Route
      metadata:
        labels:
          app: "{{ _deployed_guide_name }}"
        name: "{{ _deployed_guide_name }}"
        namespace: "{{labguide_project_name}}"
      spec:
        port:
          targetPort: 8080-tcp
        to:
          kind: Service
          name: "{{ _deployed_guide_name }}"
          weight: 100
        wildcardPolicy: None
  when:
    - guide_exists.resources | list | length < 1
 
# - name: Clean temp directory
#   file:
#     state: absent
#     path: "/tmp/{{lab_name}}"
 
 
# - name: Check that the binary doesn't exists
#   stat:
#     path: /tmp/{{lab_name}}/currency
#   register: stat_result
 
# - name: clone a private repository into
#   git:
#     repo: "{{_lab_code_repo}}"
#     version: master
#     dest: /tmp/{{lab_name}}
#     update: yes
#   when: stat_result.stat.exists == False
  
# - name: check if user project exists
#   k8s_facts:
#     api_version: apps.openshift.io/v1
#     kind: Project
#     name: "{{content_sources_project_name}}"
#   register: user_project_exists
 
# - name: "create {{content_sources_project_name}} project"
#   k8s:
#     state: present
#     definition:
#       apiVersion: project.openshift.io/v1
#       kind: Project
#       metadata:
#         name: "{{content_sources_project_name}}"
#   when:
#     - user_project_exists.resources | list | length < 1
 
############################################
##        OPERATOR SUBSCRIPTIONS          ##
############################################
 
# - name: Check if RedHat csc exists
#   k8s_facts:
#     api_version: operators.coreos.com/v1
#     kind: CatalogSourceConfig
#     name: installed-redhat-openshift-operators
#     namespace: openshift-marketplace
#   register: redhat_csc_exists 
 
# - debug:
#     var: redhat_csc_exists
#     verbosity: 3
 
# - name: Check if Community csc exists
#   k8s_facts:
#     api_version: operators.coreos.com/v1
#     kind: CatalogSourceConfig
#     name: installed-community-openshift-operators
#     namespace: openshift-marketplace
#   register: community_csc_exists
 
# - name: Check if AMQStreans subscription exists
#   k8s_facts:
#     api_version: operators.coreos.com/v1alpha1
#     kind: Subscription
#     name: amq-streams
#     namespace: openshift-operators
#   register: amqstreans_sub_exists
 
# - name: Check if CamelK subscription exists
#   k8s_facts:
#     api_version: operators.coreos.com/v1alpha1
#     kind: Subscription
#     name: camel-k
#     namespace: openshift-operators
#   register: camelk_sub_exists
 
 
#- name: Red Hat CSC deployment
#  shell: oc apply -f {{role_path}}/templates/installed-redhat-openshift-operators.yml -n openshift-marketplace
 
#- name: Community CSC deployment
#  shell: oc apply -f {{role_path}}/templates/installed-community-openshift-operators.yml -n openshift-marketplace
 
#- name: CamelK subscription deployment
#  shell: oc apply -f {{role_path}}/templates/camelk-subscription.yml -n openshift-operators
 
#- name: AMQ Streams subscription deployment
#  shell: oc apply -f {{role_path}}/templates/amqstreams-subscription.yml -n openshift-operators
 
##############################
##       CURRENCY           ##
##############################
 
- set_fact:
    appname: currency
 
- set_fact:
    project_name: content-sources
 
# - name: Running Pre Workload Tasks
#   import_tasks: ./workload_app.yml
#   become: "{{ become_override | bool }}"
 
- name: Check if {{project_name}} project exists
  k8s_facts:
    api_version: apps.openshift.io/v1
    kind: Project
    name: "{{project_name}}"
  register: project_exists
 
- name: Create {{labguide_project_name}} project
  k8s:
    state: present
    definition:
      apiVersion: project.openshift.io/v1
      kind: Project
      metadata:
        name: "{{project_name}}"
  when:
    - project_exists.resources | list | length < 1
 
- name: Import {{appname}} image
  shell: oc import-image quay.io/pnavascu/{{appname}}:1.0.0 -n {{project_name}} --confirm
 
- name: Deploy {{appname}} application
  shell: oc new-app -i {{appname}}:1.0.0 -n {{project_name}} 
 
- name: Create {{appname}} route 
  shell: oc expose svc/{{appname}} -n {{project_name}}
 
# - name: Check that the binary doesn't exists
#   stat:
#     path: /tmp/{{lab_name}}/{{appname}}/target/{{appname}}-1.0.0.jar
#   register: stat_result
 
# - name: Check that the binary doesn't exists
#   stat:
#     path: /tmp/{{lab_name}}/{{appname}}/target/{{appname}}-1.0.0.jar
#   register: stat_result
 
# - name: Deploy {{appname}} server II
#   shell: "mvn package"
#   args:
#     chdir: /tmp/{{lab_name}}/{{appname}}
#   when: stat_result.stat.exists == False
 
# - name: Deploy {{appname}} server I 
#   shell: "odo project set {{project_name}}"
 
# - name: Check that the odo component doesn't exist
#   stat:
#     path: /tmp/{{lab_name}}/{{appname}}/.odo
#   register: stat_result
 
# - name: Deploy {{appname}} server II
#   shell: "odo create java {{appname}} --project {{project_name}} --binary target/{{appname}}-1.0.0.jar"
#   args:
#     chdir: /tmp/{{lab_name}}/{{appname}}
#   when: stat_result.stat.exists == False
 
# - name: Deploy {{appname}} server III 
#   shell: "odo push"
#   args:
#     chdir: /tmp/{{lab_name}}/{{appname}}
 
# - name: workload tasks complete
#   debug:
#     msg: Workload Tasks completed successfully.
#   when: not silent|bool
 
 
# ####################################
# #######  CONTENT SERVER  ###########
# ####################################
 
- set_fact:
    appname: contentserver
 
- name: Import {{appname}} image
  shell: oc import-image quay.io/pnavascu/{{appname}}:1.0.0 -n openshift --confirm
 
# - name: Running Pre Workload Tasks
#   import_tasks: ./workload_app.yml
#   become: "{{ become_override | bool }}"
 
# ####################################
# #########  SVC REGISTRY  ###########
# ####################################
 
- set_fact:
    appname: serviceregistry
 
- name: Import {{appname}} image
  shell: oc import-image quay.io/pnavascu/{{appname}}:1.0.0 -n openshift --confirm
 
# - name: Running Pre Workload Tasks
#   import_tasks: ./workload_app.yml
#   become: "{{ become_override | bool }}"
 
# - name: workload tasks complete
#   debug:
#     msg: "Workload Tasks completed successfully."
 
#   when: not silent|bool