ansible/roles/ocp-workload-gogs-load-repository/defaults/main.yml
New file @@ -0,0 +1,29 @@ --- become_override: False ocp_username: user-redhat.com silent: False tmp_dir: /tmp/{{ guid }} tmp_kubeconfig: "{{ tmp_dir }}/.kube/config" gogs_project: "gogs" gogs_app_name: "gogs" gogs_admin_user: gogs gogs_admin_password: gogs gogs_password: gogs gogs_deploy_retry_count: 30 gogs_deploy_retry_delay: 10 gogs_generate_user_format: user%d # TODO: Check if this should be user_count instead num_users: 20 # AS A USER, YOU SHOULD PROVIDE THE VARS BELOW repositories: - base: https://github.com/openshift-roadshow name: nationalparks - base: https://github.com/openshift-roadshow name: nationalparks-py - base: https://github.com/openshift-roadshow name: nationalparks-php - base: https://github.com/openshift-roadshow name: nationalparks-js ansible/roles/ocp-workload-gogs-load-repository/readme.adoc
New file @@ -0,0 +1,67 @@ = ocp-workload-gogs-load-repository - Workload Role to create users and load repositories into Gogs == Role overview Populates an instance of gogs 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="ocp-workload-gogs-load-repository" 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-gogs-load-repository" 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/ocp-workload-gogs-load-repository/tasks/clone_repo.yml
New file @@ -0,0 +1,31 @@ --- - name: Check if repository {{ repository.name }} exists in git for user "{{ my_user }}" uri: url: http://{{ gogs_hostname }}/api/v1/repos/{{ my_user }}/{{ repository.name }} user: "{{ my_user }}" password: "{{ gogs_password }}" force_basic_auth: true status_code: 200,404 register: repo_result - name: Create git repository {{ repository.name }} for user "{{ my_user }}" uri: url: http://{{ gogs_hostname }}/api/v1/user/repos method: POST body: '{"name": "{{ repository.name }}", "private": false}' body_format: json user: "{{ my_user }}" password: "{{ gogs_password }}" status_code: 200,201 force_basic_auth: true when: repo_result.status != 200 - name: Push {{ repository.name }} to git repository in Gogs for user "{{ my_user }}" shell: | git remote add {{ my_user }} http://{{ my_user }}:{{ gogs_password }}@{{ gogs_hostname }}/{{ my_user }}/{{ repository.name }}.git git config --local user.email "{{ my_user }}@example.com" git config --local user.name "{{ my_user }}" git push -f --all {{ my_user }} args: chdir: "{{ tmp_dir }}/{{ repository.name }}" when: repo_result.status != 200 ansible/roles/ocp-workload-gogs-load-repository/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/ocp-workload-gogs-load-repository/tasks/post_workload.yml
New file @@ -0,0 +1,36 @@ --- # Implement your Post Workload deployment tasks here - name: Remove temp kube config file: path: "{{ tmp_kubeconfig }}" state: absent - name: Remove repositories file: path: "{{ tmp_dir }}/{{ repository.name }}" state: absent with_items: "{{ repositories }}" loop_control: loop_var: repository # 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/ocp-workload-gogs-load-repository/tasks/pre_workload.yml
New file @@ -0,0 +1,43 @@ --- # 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 - name: Create repositories git: repo: "{{ repository.base }}/{{ repository.name }}" dest: "{{ tmp_dir }}/{{ repository.name }}" force: true with_items: "{{ repositories }}" loop_control: loop_var: repository # 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/ocp-workload-gogs-load-repository/tasks/remove_workload.yml
New file @@ -0,0 +1,8 @@ --- # 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 ansible/roles/ocp-workload-gogs-load-repository/tasks/user_workload.yml
New file @@ -0,0 +1,35 @@ --- # Implement your Workload deployment tasks here - name: Setting up workload for user debug: msg: "Setting up workload for user = {{ my_user }}" - name: Create user and load user repository environment: KUBECONFIG: "{{ tmp_kubeconfig }}" block: - name: Create user uri: url: http://{{ gogs_hostname }}/api/v1/admin/users method: POST body: "{'login_name': '{{ my_user }}', 'username': '{{ my_user }}', 'email': '{{ my_user }}@gogs.com', 'password': '{{ gogs_password }}'}" body_format: json user: "{{ gogs_admin_user }}" password: "{{ gogs_admin_password }}" status_code: 200,201 force_basic_auth: true ignore_errors: true # Clone required project in Gogs # - name: Create repositories include_tasks: clone_repo.yml with_items: "{{ repositories }}" loop_control: loop_var: repository # 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/ocp-workload-gogs-load-repository/tasks/workload.yml
New file @@ -0,0 +1,46 @@ --- # Implement your Workload deployment tasks here - name: Setting up workload for user debug: msg: "Setting up workload for user ocp_username = {{ ocp_username }}" - name: Create user and load user repository environment: KUBECONFIG: "{{ tmp_kubeconfig }}" block: - name: Retrieve gogs route k8s_facts: api_version: "route.openshift.io/v1" kind: Route name: "{{ gogs_app_name }}" namespace: "{{ gogs_project }}" register: r_route - name: Get gogs route hostname set_fact: gogs_hostname: "{{ r_route.resources[0].spec.host }}" - name: wait for gogs to be running uri: url: http://{{ gogs_hostname }} status_code: 200 register: result until: result.status == 200 retries: "{{ gogs_deploy_retry_count }}" delay: "{{ gogs_deploy_retry_delay }}" # Clone required project in Gogs # - name: Create all users and clone their repositories include_tasks: user_workload.yml with_sequence: start=1 end={{ num_users }} format="{{ gogs_generate_user_format }}" when: num_users > 0 loop_control: loop_var: my_user # 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/ocp-workload-gogs-load-repository/tests/test-local.yml
New file @@ -0,0 +1,9 @@ --- - hosts: localhost connection: local remote_user: root vars: # become_override: false guid: abcde12345 tmp_dir: /tmp/sampleuser # ocp_username: opentlc-mgr