Jorge Morales Pou
2019-11-22 50a0e2a832e1ed8b033535d0f4e7c75fbbfb6d08
Workshop tracker for OSEVG team (#875)

8 files added
232 ■■■■■ changed files
ansible/roles/ocp4-workload-osevg-workshop-tracker/defaults/main.yml 13 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-osevg-workshop-tracker/readme.adoc 67 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-osevg-workshop-tracker/tasks/main.yml 30 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-osevg-workshop-tracker/tasks/post_workload.yml 28 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-osevg-workshop-tracker/tasks/pre_workload.yml 34 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-osevg-workshop-tracker/tasks/remove_workload.yml 12 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-osevg-workshop-tracker/tasks/workload.yml 38 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-osevg-workshop-tracker/tests/test-local.yml 10 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-osevg-workshop-tracker/defaults/main.yml
New file
@@ -0,0 +1,13 @@
---
become_override: False
ocp_username: user-redhat.com
silent: False
tmp_dir: /tmp/{{ guid }}
tmp_kubeconfig: "{{ tmp_dir }}/.kube/config"
cluster_name:
cluster_version:
# Variables to change per invocation.
num_users: 15
workshop_type: starter
ansible/roles/ocp4-workload-osevg-workshop-tracker/readme.adoc
New file
@@ -0,0 +1,67 @@
= ocp4-workload-osevg-workshop-tracker - Workshop Tracker for OSEVG Workshops on OCP 4 Workload Role
== Role overview
Records the provisioning of the workshop developed by OSEVG team on your cluster.
== Review the defaults variable file
* This file link:./defaults/main.yml[./defaults/main.yml] contains all the variables you need to define to control the deployment of your workload.
* The variable *ocp_username* is mandatory to assign the workload to the correct OpenShift user.
* A variable *silent=True* can be passed to suppress debug messages.
* You can modify any of these default values by adding `-e "variable_name=variable_value"` to the command line
=== Deploy a Workload with the `ocp-workload` playbook [Mostly for testing]
----
TARGET_HOST="bastion.na39.openshift.opentlc.com"
OCP_USERNAME="shacharb-redhat.com"
WORKLOAD="ocp4-workload-osevg-workshop-tracker"
GUID=1001
# a TARGET_HOST is specified in the command line, without using an inventory file
ansible-playbook -i ${TARGET_HOST}, ./configs/ocp-workloads/ocp-workload.yml \
    -e"ansible_ssh_private_key_file=~/.ssh/keytoyourhost.pem" \
    -e"ansible_user=ec2-user" \
    -e"ocp_username=${OCP_USERNAME}" \
    -e"ocp_workload=${WORKLOAD}" \
    -e"silent=False" \
    -e"guid=${GUID}" \
    -e"ACTION=create"
----
=== To Delete an environment
----
TARGET_HOST="bastion.na39.openshift.opentlc.com"
OCP_USERNAME="ankay-redhat.com"
WORKLOAD="ocp4-workload-osevg-workshop-tracker"
GUID=1002
# a TARGET_HOST is specified in the command line, without using an inventory file
ansible-playbook -i ${TARGET_HOST}, ./configs/ocp-workloads/ocp-workload.yml \
    -e"ansible_ssh_private_key_file=~/.ssh/keytoyourhost.pem" \
    -e"ansible_user=ec2-user" \
    -e"ocp_username=${OCP_USERNAME}" \
    -e"ocp_workload=${WORKLOAD}" \
    -e"guid=${GUID}" \
    -e"ACTION=remove"
----
== Other related information:
=== Deploy Workload on OpenShift Cluster from an existing playbook:
[source,yaml]
----
- name: Deploy a workload role on a master host
  hosts: all
  become: true
  gather_facts: False
  tags:
    - step007
  roles:
    - { role: "{{ocp_workload}}", when: 'ocp_workload is defined' }
----
NOTE: You might want to change `hosts: all` to fit your requirements
ansible/roles/ocp4-workload-osevg-workshop-tracker/tasks/main.yml
New file
@@ -0,0 +1,30 @@
---
# Do not modify this file
- name: Running Pre Workload Tasks
  include_tasks:
    file: ./pre_workload.yml
    apply:
      become: "{{ become_override | bool }}"
  when: ACTION == "create" or ACTION == "provision"
- name: Running Workload Tasks
  include_tasks:
    file: ./workload.yml
    apply:
      become: "{{ become_override | bool }}"
  when: ACTION == "create" or ACTION == "provision"
- name: Running Post Workload Tasks
  include_tasks:
    file: ./post_workload.yml
    apply:
      become: "{{ become_override | bool }}"
  when: ACTION == "create" or ACTION == "provision"
- name: Running Workload removal Tasks
  include_tasks:
    file: ./remove_workload.yml
    apply:
      become: "{{ become_override | bool }}"
  when: ACTION == "destroy" or ACTION == "remove"
ansible/roles/ocp4-workload-osevg-workshop-tracker/tasks/post_workload.yml
New file
@@ -0,0 +1,28 @@
---
# Implement your Post Workload deployment tasks here
- name: Remove temp kube config
  file:
    path: "{{ tmp_dir }}"
    state: absent
# Leave these as the last tasks in the playbook
# For deployment onto a dedicated cluster (as part of the
# cluster deployment) set workload_shared_deployment to False
# This is the default so it does not have to be set explicitely
- name: pre_workload tasks complete
  debug:
    msg: "Post-Workload tasks completed successfully."
  when:
  - not silent|bool
  - not workload_shared_deployment|d(False)
# For RHPDS deployment (onto a shared cluster) set
# workload_shared_deployment to True
# (in the deploy script or AgnosticV configuration)
- name: pre_workload tasks complete
  debug:
    msg: "Post-Software checks completed successfully"
  when:
  - not silent|bool
  - workload_shared_deployment|d(False)
ansible/roles/ocp4-workload-osevg-workshop-tracker/tasks/pre_workload.yml
New file
@@ -0,0 +1,34 @@
---
# Implement your Pre Workload deployment tasks here
- name: Ensure directory exists
  file:
    path: "{{ tmp_dir }}"
    state: directory
- name: Copy .kube/config and set env var
  copy:
    src: ~/.kube
    dest: "{{ tmp_dir }}"
    remote_src: yes
# Leave these as the last tasks in the playbook
# For deployment onto a dedicated cluster (as part of the
# cluster deployment) set workload_shared_deployment to False
# This is the default so it does not have to be set explicitely
- name: pre_workload tasks complete
  debug:
    msg: "Pre-Workload tasks completed successfully."
  when:
  - not silent|bool
  - not workload_shared_deployment|d(False)
# For RHPDS deployment (onto a shared cluster) set
# workload_shared_deployment to True
# (in the deploy script or AgnosticV configuration)
- name: pre_workload tasks complete
  debug:
    msg: "Pre-Software checks completed successfully"
  when:
  - not silent|bool
  - workload_shared_deployment|d(False)
ansible/roles/ocp4-workload-osevg-workshop-tracker/tasks/remove_workload.yml
New file
@@ -0,0 +1,12 @@
---
# Implement your Workload removal tasks here
- name: Ensure directory exists
  file:
    path: "{{ tmp_dir }}"
    state: directory
# Leave this as the last task in the playbook.
- name: remove_workload tasks complete
  debug:
    msg: "Remove Workload tasks completed successfully."
  when: not silent|bool
ansible/roles/ocp4-workload-osevg-workshop-tracker/tasks/workload.yml
New file
@@ -0,0 +1,38 @@
---
# Implement your Workload deployment tasks here
- name: Setting up workload for user
  debug:
    msg: "Setting up workload for user ocp_username = {{ ocp_username }}"
- environment:
    KUBECONFIG: "{{ tmp_kubeconfig }}"
  block:
    - name: Get DNS
      command: oc get DNS/cluster -o jsonpath='{ .spec.baseDomain }'
      register: __base_domain
    - name: Get Version
      command: oc get ClusterVersion/version -o jsonpath='{ .spec.channel }'
      register: __version
    - name: extract cluster name
      set_fact:
        cluster_name: "{{ __base_domain.stdout }}"
        cluster_version: "{{ __version.stdout }}"
      ignore_errors: true
    # track workshop deployment
    - name: track workshop deployment
      shell: "curl https://docs.google.com/forms/d/e/1FAIpQLSeB07chJxLPln8xIeYia-A8s3fmkQUBY-RVgh5Fbw12JHAp8g/formResponse -d ifq -d entry.2085252894={{ workshop_type }} -d entry.1606494704={{ cluster_name }} -d entry.747754363={{ cluster_version }} -d entry.2012508525={{ num_users }} -d submit=Submit 1> /dev/null"
      when:
        - cluster_name is not none
        - cluster_name|trim() != ""
      ignore_errors: true
# Leave this as the last task in the playbook.
- name: workload tasks complete
  debug:
    msg: "Workload Tasks completed successfully."
  when: not silent|bool
ansible/roles/ocp4-workload-osevg-workshop-tracker/tests/test-local.yml
New file
@@ -0,0 +1,10 @@
---
- hosts: localhost
  connection: local
  remote_user: root
  vars:
#    become_override: false
    guid: abcde12345
    tmp_kubeconfig: /tmp/{{ guid }}/kube-config
    tmp_git_location: /tmp/{{ guid }}/git
#    ocp_username: opentlc-mgr