--- - name: Setting up workload for user debug: msg: "Setting up workload for user ocp_username = {{ ocp_username }}" - environment: KUBECONFIG: "{{ tmp_kubeconfig }}" block: - name: Create Project {{ project_name }} k8s: state: present definition: "{{ lookup('template', item ) | from_yaml }}" loop: - ./templates/project.j2 register: r_createproject until: r_createproject is succeeded retries: 5 - environment: KUBECONFIG: "{{ tmp_kubeconfig }}" vars: __homeroom_installed: False block: - name: "Get homeroom deployment (fact)" k8s_facts: api_version: "apps.openshift.io/v1" kind: DeploymentConfig name: "homeroom" namespace: "{{ project_name }}" register: __homeroom_dc - name: "Get homeroom deployment (value)" debug: var: __homeroom_dc verbosity: 1 - name: "Is homeroom installed (fact)" set_fact: __homeroom_installed: "{{ __homeroom_dc.resources[0].status.replicas == 1 | default(false) | bool }}" when: __homeroom_dc.resources is defined and (__homeroom_dc.resources|length>0) - name: Is homeroom installed (value) debug: var: __homeroom_installed verbosity: 1 - name: Deploy homeroom block: - name: Create homeroom resources shell: > oc process -f {{ homeroom_template_path }} \ --param APPLICATION_NAME="homeroom" | oc apply -n {{ project_name }} -f - when: not __homeroom_installed - name: Wait for the homeroom to deploy command: oc rollout status dc/homeroom -n {{ project_name }} when: not __homeroom_installed - name: Git clone the repo if it doesn't exist git: repo: "{{ lab_repo }}" version: "{{ lab_branch }}" dest: "{{ tmp_git_location }}" force: true track_submodules: yes - name: Deploy workshop include_tasks: deploy_workshop.yml loop: - java - python - php - javascript # For PHP we need an image with the mongodb driver - name: "Copy updated PHP+mongodb IS to temp" block: - copy: src: php-is.yml dest: "{{ tmp_dir }}/php-is.yml" - command: "oc replace -f php-is.yml -n openshift" 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: "" ## Enable logging on the cluster - name: Create OpenShift Objects for logging ignore_errors: yes retries: 5 delay: 10 until: r_objects is succeeded register: r_objects k8s: state: present merge_type: - strategic-merge - merge definition: "{{ lookup('file', item ) | from_yaml }}" loop: - ./files/eo-namespace.yml - ./files/clo-namespace.yml - ./files/eo-og.yml - ./files/eo-sub.yml - ./files/eo-role.yml - ./files/eo-rb.yml - ./files/clo-og.yml - ./files/clo-sub.yml - name: Wait for Elasticsearch CRD k8s_facts: api_version: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition name: elasticsearches.logging.openshift.io register: r_elasticsearch_crd retries: 20 delay: 10 ignore_errors: yes until: r_elasticsearch_crd.resources | list | length == 1 - name: Notify user if Elasticsearch deployment failed when: not r_elasticsearch_crd.resources | list | length == 1 debug: msg: "user.info: *** Elasticsearch operator could not be installed ***" - name: Wait for Logging CRD k8s_facts: api_version: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition name: clusterloggings.logging.openshift.io register: r_logging_crd retries: 20 delay: 10 ignore_errors: yes until: r_logging_crd.resources | list | length == 1 - name: Notify user if Logging deployment failed when: not r_logging_crd.resources | list | length == 1 debug: msg: "user.info: *** Logging operator could not be installed ***" - name: Deploy Logging when: - r_logging_crd.resources | list | length == 1 - r_elasticsearch_crd.resources | list | length == 1 block: - name: Create OpenShift Objects for ClusterLogging k8s: state: present merge_type: - strategic-merge - merge definition: "{{ lookup('template', item ) | from_yaml }}" ignore_errors: yes loop: - ./files/cl-instance.yml # Leave this as the last task in the playbook. - name: workload tasks complete debug: msg: "Workload Tasks completed successfully." when: not silent|bool