Jan Kleinert
2020-03-10 3fb4490e472d147d6a47fe30cd020d63b5f459f4
commit | author | age
3668a7 1 ---
JMP 2 - name: Setting up workload for user
3   debug:
4     msg: "Setting up workload for user ocp_username = {{ ocp_username }}"
5
6 - environment:
7     KUBECONFIG: "{{ tmp_kubeconfig }}"
8   block:
9     - name: Create Project {{ project_name }}
10       k8s:
11         state: present
12         definition: "{{ lookup('template', item ) | from_yaml }}"
13       loop:
14       - ./templates/project.j2
15       register: r_createproject
16       until: r_createproject is succeeded
17       retries: 5
18
19 - environment:
20     KUBECONFIG: "{{ tmp_kubeconfig }}"
21   vars:
22     __homeroom_installed: False
23   block:
24     - name: "Get homeroom deployment (fact)"
25       k8s_facts:
26         api_version: "apps.openshift.io/v1"
27         kind: DeploymentConfig
28         name: "homeroom"
29         namespace: "{{ project_name }}"
30       register: __homeroom_dc
31
32     - name: "Get homeroom deployment (value)"
33       debug: 
34         var: __homeroom_dc
35         verbosity: 1
36
37     - name: "Is homeroom installed (fact)"
38       set_fact:
39         __homeroom_installed: "{{ __homeroom_dc.resources[0].status.replicas == 1 | default(false) | bool }}"
40       when: __homeroom_dc.resources is defined and (__homeroom_dc.resources|length>0)
41     
42     - name: Is homeroom installed (value)
43       debug:
44         var: __homeroom_installed
45         verbosity: 1
46
47     - name: Deploy homeroom
48       block:
49         - name: Create homeroom resources
50           shell: >
51             oc process -f {{ homeroom_template_path }} \
52             --param APPLICATION_NAME="homeroom" | oc apply -n {{ project_name }} -f -
53           when: not __homeroom_installed
54
55         - name: Wait for the homeroom to deploy
56           command: oc rollout status dc/homeroom -n {{ project_name }}
57           when: not __homeroom_installed
58
59 - name: Git clone the repo if it doesn't exist
60   git:
61     repo: "{{ lab_repo }}"
62     version: "{{ lab_branch }}"
63     dest: "{{ tmp_git_location }}"
64     force: true
65     track_submodules: yes
66
67 - name: Deploy workshop
68   include_tasks: deploy_workshop.yml
69   loop:
70     - java
71     - python
72     - php
73     - javascript
74
a353e7 75 # For PHP we need an image with the mongodb driver
3668a7 76 - name: "Copy updated PHP+mongodb IS to temp"
JMP 77   block:
78     - copy:
79         src: php-is.yml
80         dest: "{{ tmp_dir }}/php-is.yml"
81     - command: "oc replace -f php-is.yml -n openshift"
82       args:
83         chdir: "{{ tmp_dir }}"
84
a353e7 85 - name: Create all users and projects with correct permissions 
JK 86   include_tasks: per_user.yml
87   with_sequence: start={{user_count_start}} end={{ user_count_end }} format={{ user_format }}
88   loop_control:
89     loop_var: my_user
90
91 - name: Get Nexus route hostname
92   environment:
93     KUBECONFIG: "{{ tmp_kubeconfig }}"
94   block:
95     - name: Retrieve nexus route
96       k8s_facts:
97         api_version: "route.openshift.io/v1"
98         kind: Route
99         name: "nexus"
100         namespace: "{{ project_name }}"
101       register: r_route
102
103     - name: Get nexus route hostname
104       set_fact:
105         nexus_route: "{{ r_route.resources[0].spec.host }}"
106
107 - name: Remove (potential) previously declared snapshots Groovy script for Nexus
108   uri:
109     url: "http://{{nexus_route}}/service/rest/v1/script/snapshots"
110     user: 'admin'
111     password: "admin123"
112     method: DELETE
113     force_basic_auth: yes
114     status_code: 204,404
115  
116 - name: Declaring snapshots Groovy script 
117   uri:
118     url: "http://{{nexus_route}}/service/rest/v1/script"
119     user: 'admin'
120     password: "admin123"
121     body_format: json
122     method: POST
123     force_basic_auth: yes
124     status_code: 204
125     body:
126       name: "snapshots"
127       type: 'groovy'
128       content: "import org.sonatype.nexus.blobstore.api.BlobStoreManager\nimport org.sonatype.nexus.repository.storage.WritePolicy\nimport org.sonatype.nexus.repository.maven.VersionPolicy\nimport org.sonatype.nexus.repository.maven.LayoutPolicy\nrepository.createMavenHosted('maven-snapshots', BlobStoreManager.DEFAULT_BLOBSTORE_NAME, true, VersionPolicy.SNAPSHOT, WritePolicy.ALLOW, LayoutPolicy.STRICT)"
129       
130
131 - name: Call Groovy script snapshots
132   uri:
133     url: "http://{{nexus_route}}/service/rest/v1/script/snapshots/run"
134     user: 'admin'
135     password: 'admin123'
136     headers:
137       Content-Type: "text/plain"
138     method: POST
139     status_code: 200,204
140     force_basic_auth: yes
141     body: ""
142
3668a7 143 # Leave this as the last task in the playbook.
JMP 144 - name: workload tasks complete
145   debug:
146     msg: "Workload Tasks completed successfully."
147   when: not silent|bool