From b727c03c3ade2cd66b35fa0d354f933707441ffe Mon Sep 17 00:00:00 2001 From: joelbirchler <jbirchler@redhat.com> Date: Mon, 02 Mar 2020 23:25:55 +0100 Subject: [PATCH] WIP workloads imports correctly but is messy --- /dev/null | 18 ------------------ ansible/configs/ansible-skylight/workloads.yml | 32 +++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/ansible/configs/ansible-skylight/workloads.yml b/ansible/configs/ansible-skylight/workloads.yml index a22ab68..7a7fd1f 100644 --- a/ansible/configs/ansible-skylight/workloads.yml +++ b/ansible/configs/ansible-skylight/workloads.yml @@ -1,18 +1,40 @@ --- +- name: Clone private workloads + hosts: localhost + gather_facts: false + run_once: true + become: false + tasks: + - name: Create and pull repo + shell: | + source_path=/tmp/{{ item.name }}-private-workload + workload_path=$(pwd)/../../roles/{{ item.name }}-private-workload + + mkdir -p $source_path && cd $source_path + + git init + git remote add origin {{ item.url }} + + git config core.sparseCheckout true + echo "{{ item.path }}" >> .git/info/sparse-checkout + + git pull --depth=1 origin master + + ln -s $source_path/{{ item.path }} $workload_path + + exit 0 + loop: "{{ private_workloads }}" + - name: Install workloads hosts: bastions gather_facts: false run_once: true become: false - tasks: - name: Include private workloads include_role: - name: "{{ item.tmp }}" + name: "{{ item.name }}-private-workload" vars: ACTION: "provision" workload_name: "{{ item.name }}" - workload_git_url: "{{ item.url }}" - workload_git_path: "{{ item.path }}" - workload_ssh_key: "{{ item.ssh_key }}" loop: "{{ private_workloads }}" \ No newline at end of file diff --git a/ansible/roles/agnosticd-workload/defaults/main.yml b/ansible/roles/agnosticd-workload/defaults/main.yml deleted file mode 100644 index 9637227..0000000 --- a/ansible/roles/agnosticd-workload/defaults/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -become_override: False -silent: False diff --git a/ansible/roles/agnosticd-workload/readme.adoc b/ansible/roles/agnosticd-workload/readme.adoc deleted file mode 100644 index 8fd49c2..0000000 --- a/ansible/roles/agnosticd-workload/readme.adoc +++ /dev/null @@ -1,117 +0,0 @@ -= ocp-workload-example - Example Workload Role - -== Role overview - -* This is a working no-op role that can be used to develop new ocp-workload roles. It consists of the following playbooks: -** Playbook: link:./tasks/pre_workload.yml[pre_workload.yml] - Sets up an - environment for the workload deployment -*** Debug task will print out: `pre_workload Tasks completed successfully.` - -** Playbook: link:./tasks/workload.yml[workload.yml] - Used to deploy the actual - workload, i.e, 3scale, Mobile or some Demo -*** This role only prints the current username for which this role is provisioning. -*** Debug task will print out: `workload Tasks completed successfully.` - -** Playbook: link:./tasks/post_workload.yml[post_workload.yml] - Used to - configure the workload after deployment -*** This role doesn't do anything here -*** Debug task will print out: `post_workload Tasks completed successfully.` - -** Playbook: link:./tasks/remove_workload.yml[remove_workload.yml] - Used to - delete the workload -*** This role doesn't do anything here -*** Debug task will print out: `remove_workload Tasks completed successfully.` - -== 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="ocp-workload-example" -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="ocp-workload-example" -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 - - -=== Set up your Ansible inventory file - -* You can create an Ansible inventory file to define your connection method to your host (Master/Bastion with `oc` command) -* You can also use the command line to define the hosts directly if your `ssh` configuration is set to connect to the host correctly -* You can also use the command line to use localhost or if your cluster is already authenticated and configured in your `oc` configuration - -.Example inventory file -[source, ini] ----- -[gptehosts:vars] -ansible_ssh_private_key_file=~/.ssh/keytoyourhost.pem -ansible_user=ec2-user - -[gptehosts:children] -openshift - -[openshift] -bastion.cluster1.openshift.opentlc.com -bastion.cluster2.openshift.opentlc.com -bastion.cluster3.openshift.opentlc.com -bastion.cluster4.openshift.opentlc.com - -[dev] -bastion.cluster1.openshift.opentlc.com -bastion.cluster2.openshift.opentlc.com - -[prod] -bastion.cluster3.openshift.opentlc.com -bastion.cluster4.openshift.opentlc.com ----- diff --git a/ansible/roles/agnosticd-workload/tasks/gitlab.yml b/ansible/roles/agnosticd-workload/tasks/gitlab.yml deleted file mode 100644 index 8fa89dc..0000000 --- a/ansible/roles/agnosticd-workload/tasks/gitlab.yml +++ /dev/null @@ -1,149 +0,0 @@ ---- -- name: Remove repo directory - file: - path: /tmp/do417 - state: absent - -- name: Install acl - yum: - name: acl - state: present - use_backend: dnf - become: true - -- name: Get ssh key for Github - copy: - src: "{{ github_ssh_key }}" - dest: /tmp/github_ssh_key - mode: 0400 - owner: "{{ ansible_user }}" - -- name: Get lab source code - git: - clone: yes - force: yes - dest: "/tmp/do417" - repo: "git@github.com:RedHatTraining/do417.git" - key_file: /tmp/github_ssh_key - accept_hostkey: true - -- name: Remove ssh key for Github - file: - path: /tmp/github_ssh_key - state: absent - -- name: Remove .git directory - file: - path: /tmp/do417/.git - state: absent - -- name: Determining material directories - command: find /tmp/do417/classroom/infrastructure/playbooks/files/src -maxdepth 1 -mindepth 1 -type d -printf '%f\n' - register: repos_name - -- name: Retrieve access token - uri: - url: "https://gitlab.{{zone_internal_dns}}/oauth/token" - method: POST - validate_certs: no - status_code: 200 - body_format: json - headers: - Content-Type: application/json - body: > - { - "grant_type": "password", - "username": "root", - "password": "{{ windows_password }}" - } - register: gitlab_access_token - -- name: Retrieve local user information via API - uri: - url: https://gitlab.{{zone_internal_dns}}/api/v4/users?username={{ user_prefix }} - method: GET - validate_certs: no - status_code: - - 200 - - 201 - headers: - Content-Type: application/json - Authorization: Bearer {{ gitlab_access_token.json.access_token }} - register: gitlab_local_users - -- name: Create projects via API - uri: - url: https://gitlab.{{zone_internal_dns}}/api/v4/projects/user/{{ gitlab_local_users.json[0].id }} - method: POST - validate_certs: no - status_code: - - 200 - - 201 - - 409 - - 400 - body_format: json - headers: - Content-Type: application/json - Authorization: Bearer {{ gitlab_access_token.json.access_token }} - body: > - { - "name": "{{ item }}", - "group": "{{ gitlab_local_users.json[0].name }}", - "issues_enabled": false, - "wiki_enabled": true, - "snippets_enabled": true - } - with_items: "{{ repos_name.stdout_lines }}" - when: gitlab_local_users.json[0].id is defined - -- name: Configure local account - shell: | - git config --global http.sslVerify false - git config --global user.email student@example.com - git config --global user.name student - -- name: Delete previous directories if present - file: - path: "/tmp/{{��item }}" - state: absent - with_items: "{{ repos_name.stdout_lines }}" - -- name: Clone repositories - git: - repo: https://{{ user_prefix | urlencode }}:{{ windows_password | urlencode }}@gitlab.{{zone_internal_dns}}/student/{{��item }}.git - dest: "/tmp/{{��item }}/" - clone: yes - with_items: "{{ repos_name.stdout_lines }}" - ignore_errors: true - -- name: Copying files for repositories - copy: - src: "/tmp/do417/classroom/infrastructure/playbooks/files/src/{{ item }}/" - dest: "/tmp/{{ item }}/" - remote_src: true - with_items: "{{ repos_name.stdout_lines }}" - -- name: ({{ repo_name }}) - Creating dummy file - copy: - dest: "/tmp/{{ item }}/dummy.yml" - content: | - --- - - name: Dummy playbook - hosts: all - tasks: - - name: Print Hello World - debug: - msg: 'Hello World' - with_items: "{{ repos_name.stdout_lines }}" - -- name: Load files into repositories - shell: | - git init - git remote add origin https://{{ user_prefix | urlencode }}:{{ windows_password | urlencode }}@gitlab.{{zone_internal_dns}}/student/{{��item }}.git - git add . - git commit -m 'Establish initial {{ item }} repository' - git push -u origin HEAD:master - exit 0 - args: - chdir: "/tmp/{{ item }}" - with_items: "{{��repos_name.stdout_lines }}" diff --git a/ansible/roles/agnosticd-workload/tasks/main.yml b/ansible/roles/agnosticd-workload/tasks/main.yml deleted file mode 100644 index 03a4801..0000000 --- a/ansible/roles/agnosticd-workload/tasks/main.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -# 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" diff --git a/ansible/roles/agnosticd-workload/tasks/post_workload.yml b/ansible/roles/agnosticd-workload/tasks/post_workload.yml deleted file mode 100644 index 9a07468..0000000 --- a/ansible/roles/agnosticd-workload/tasks/post_workload.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -# Implement your Post Workload deployment tasks here - -# 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) \ No newline at end of file diff --git a/ansible/roles/agnosticd-workload/tasks/pre_workload.yml b/ansible/roles/agnosticd-workload/tasks/pre_workload.yml deleted file mode 100644 index 00b8605..0000000 --- a/ansible/roles/agnosticd-workload/tasks/pre_workload.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -# Implement your Pre Workload deployment tasks here - -# 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) diff --git a/ansible/roles/agnosticd-workload/tasks/remove_workload.yml b/ansible/roles/agnosticd-workload/tasks/remove_workload.yml deleted file mode 100644 index 69e426f..0000000 --- a/ansible/roles/agnosticd-workload/tasks/remove_workload.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -# Implement your Workload removal tasks here - - -# 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 diff --git a/ansible/roles/agnosticd-workload/tasks/workload.yml b/ansible/roles/agnosticd-workload/tasks/workload.yml deleted file mode 100644 index d0714f9..0000000 --- a/ansible/roles/agnosticd-workload/tasks/workload.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- - -- name: Setting up workload - debug: - msg: "Setting up workload {{ workload_name }}." - when: not silent|bool - -- name: Setting up GitLab - include_tasks: gitlab.yml - -- name: Setting up Tower - include_tasks: tower.yml - -# Leave this as the last task in the playbook. -- name: workload tasks complete - debug: - msg: "Workload Tasks completed successfully." - when: not silent|bool -- Gitblit v1.9.3