Jan Kleinert
2020-01-20 a353e7f7a21a337e2a36cb0f93c7be3b89de1fc4
Updates to starter workshop for user projects/permissions and Nexus fixes (#1018)

1 files added
3 files modified
103 ■■■■■ changed files
ansible/roles/ocp4-workload-homeroomlab-starter-guides/defaults/main.yml 5 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-homeroomlab-starter-guides/tasks/per_user.yml 35 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-homeroomlab-starter-guides/tasks/pre_workload.yml 3 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-homeroomlab-starter-guides/tasks/workload.yml 60 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-homeroomlab-starter-guides/defaults/main.yml
@@ -13,3 +13,8 @@
lab_branch: ocp-4.2
homeroom_template_path: "https://raw.githubusercontent.com/openshift-homeroom/workshop-homeroom/2.1.0/templates/production.json"
openshift_cli: oc
user_count_start: 1
num_users: 20
user_format: user%d
ansible/roles/ocp4-workload-homeroomlab-starter-guides/tasks/per_user.yml
New file
@@ -0,0 +1,35 @@
---
- name: per user
  block:
    - name: per_user {{my_user}} Tasks Started
      debug:
        msg: "per_user {{my_user}} Tasks - Started"
    # Create user project and make it admin
    - name: check if workshop user's project for user "{{ my_user }}" exists
      shell: "{{ openshift_cli }} get project {{ my_user }}"
      register: user_project
      ignore_errors: true
      changed_when: false
      tags: always
    - name: Create workshop user's project for user "{{ my_user }}"
      command: "{{ openshift_cli }} adm new-project {{ my_user }}"
      when: user_project is failed
      tags: always
    - name: Annotate the project as requested by user for user "{{ my_user }}"
      command: "{{ openshift_cli }} annotate namespace {{my_user}} openshift.io/requester={{my_user}} --overwrite"
      tags: always
    - name: Award admin permission for user "{{ my_user }}"
      command: "{{ openshift_cli }} adm policy add-role-to-user admin {{ my_user }} -n {{ my_user }}"
      tags: always
    - name: Add cluster-role cluster-monitoring-view for user "{{ my_user }}"
      command: "{{ openshift_cli }} adm policy add-cluster-role-to-user cluster-monitoring-view {{ my_user }}"
      tags: always
    - name: per_user {{my_user}} Tasks Complete
      debug:
        msg: "per_user {{my_user}} Tasks - Completed"
ansible/roles/ocp4-workload-homeroomlab-starter-guides/tasks/pre_workload.yml
@@ -1,4 +1,7 @@
---
- set_fact:
    user_count_end: "{{ (user_count_start | int) + (num_users | int) - 1 }}"
# Implement your Pre Workload deployment tasks here
- name: Ensure directory exists
  file:
ansible/roles/ocp4-workload-homeroomlab-starter-guides/tasks/workload.yml
@@ -72,7 +72,7 @@
    - php
    - javascript
# For PHP we need an image with the mongodb driver
# For PHP we need an image with the mongodb driver
- name: "Copy updated PHP+mongodb IS to temp"
  block:
    - copy:
@@ -82,6 +82,64 @@
      args:
        chdir: "{{ tmp_dir }}"
- name: Create all users and projects with correct permissions
  include_tasks: per_user.yml
  with_sequence: start={{user_count_start}} end={{ user_count_end }} format={{ user_format }}
  loop_control:
    loop_var: my_user
- name: Get Nexus route hostname
  environment:
    KUBECONFIG: "{{ tmp_kubeconfig }}"
  block:
    - name: Retrieve nexus route
      k8s_facts:
        api_version: "route.openshift.io/v1"
        kind: Route
        name: "nexus"
        namespace: "{{ project_name }}"
      register: r_route
    - name: Get nexus route hostname
      set_fact:
        nexus_route: "{{ r_route.resources[0].spec.host }}"
- name: Remove (potential) previously declared snapshots Groovy script for Nexus
  uri:
    url: "http://{{nexus_route}}/service/rest/v1/script/snapshots"
    user: 'admin'
    password: "admin123"
    method: DELETE
    force_basic_auth: yes
    status_code: 204,404
- name: Declaring snapshots Groovy script
  uri:
    url: "http://{{nexus_route}}/service/rest/v1/script"
    user: 'admin'
    password: "admin123"
    body_format: json
    method: POST
    force_basic_auth: yes
    status_code: 204
    body:
      name: "snapshots"
      type: 'groovy'
      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)"
- name: Call Groovy script snapshots
  uri:
    url: "http://{{nexus_route}}/service/rest/v1/script/snapshots/run"
    user: 'admin'
    password: 'admin123'
    headers:
      Content-Type: "text/plain"
    method: POST
    status_code: 200,204
    force_basic_auth: yes
    body: ""
# Leave this as the last task in the playbook.
- name: workload tasks complete
  debug: