Skip to content

Commit 5db35ea

Browse files
authored
Added Role to deploy applicationset using ArgoCd (#7783)
1 parent 629d9f9 commit 5db35ea

File tree

8 files changed

+216
-0
lines changed

8 files changed

+216
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
ocp_username: system:admin
3+
become_override: false
4+
silent: false
5+
6+
# ocp4_workload_argocd_bootstrap variables
7+
ocp4_workload_argocd_bootstrap_repo_url: https://github.com/rh-aiservices-bu/insurance-claim-processing.git
8+
ocp4_workload_argocd_bootstrap_branch: main
9+
ocp4_workload_argocd_bootstrap_yaml_file_path: bootstrap/applicationset/applicationset-bootstrap.yaml
10+
11+
# Workload destroy as var
12+
ocp4_workload_argocd_bootstrap_workload_destroy: "{{ False if (ACTION=='create' or ACTION=='provision') else True }}"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
galaxy_info:
3+
role_name: ocp4_workload_argocd_bootstrap
4+
author:
5+
- Ritesh Shah <[email protected]>
6+
description: OpenShift ArgoCD Bootstrap Deployment Role
7+
company: Red Hat
8+
license: BSD
9+
min_ansible_version: 2.9
10+
galaxy_tags: []
11+
12+
dependencies: []
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
= ocp4_workload_argocd_bootstrap - Workload to deploy manifest using ArgoCD on OpenShift Cluster.
2+
== Role overview
3+
4+
* This role deploy's applicationset (Single) manifest using ArgoCD on OpenShift Cluster. Ensure that Red Hat OpenShift GitOps is preinstalled.
5+
6+
This role consists of the following tasks files:
7+
** Tasks: link:./tasks/pre_workload.yml[pre_workload.yml] - Sets up an
8+
environment for the workload deployment.
9+
*** Debug task will print out: `pre_workload Tasks completed successfully.`
10+
11+
** Tasks: link:./tasks/workload.yml[workload.yml] - Used to configure the cluster
12+
*** Debug task will print out: `workload Tasks completed successfully.`
13+
14+
** Tasks: link:./tasks/post_workload.yml[post_workload.yml] - Used to
15+
configure the workload after deployment
16+
*** This role doesn't do anything here
17+
*** Debug task will print out: `post_workload Tasks completed successfully.`
18+
19+
** Tasks: link:./tasks/remove_workload.yml[remove_workload.yml] - Used to
20+
delete the workload
21+
*** Debug task will print out: `remove_workload Tasks completed successfully.`
22+
23+
== Review the defaults variable file
24+
25+
* This file link:./defaults/main.yml[./defaults/main.yml] contains all the variables you need to define to control the deployment of your workload.
26+
* The variable *ocp_username* is mandatory to assign the workload to the correct OpenShift user.
27+
* A variable *silent=True* can be passed to suppress debug messages.
28+
29+
=== Deploy a Workload with the `ocp-workload` playbook [Mostly for testing]
30+
31+
----
32+
TARGET_HOST="bastion.shared-na46.openshift.opentlc.com"
33+
OCP_USERNAME="rshah-redhat.com"
34+
WORKLOAD="ocp4_workload_argocd_bootstrap"
35+
GUID=1001
36+
37+
# a TARGET_HOST is specified in the command line, without using an inventory file
38+
ansible-playbook -i ${TARGET_HOST}, ./configs/ocp-workloads/ocp-workload.yml \
39+
-e"ansible_ssh_private_key_file=~/.ssh/keytoyourhost.pem" \
40+
-e"ansible_user=ec2-user" \
41+
-e"ocp_username=${OCP_USERNAME}" \
42+
-e"ocp_workload=${WORKLOAD}" \
43+
-e"silent=False" \
44+
-e"guid=${GUID}" \
45+
-e"ACTION=create"
46+
----
47+
48+
=== To Delete an environment
49+
50+
----
51+
TARGET_HOST="bastion.shared-na46.openshift.opentlc.com"
52+
OCP_USERNAME="rshah-redhat.com"
53+
WORKLOAD="ocp4_workload_argocd_bootstrap"
54+
GUID=1002
55+
56+
# a TARGET_HOST is specified in the command line, without using an inventory file
57+
ansible-playbook -i ${TARGET_HOST}, ./configs/ocp-workloads/ocp-workload.yml \
58+
-e"ansible_ssh_private_key_file=~/.ssh/keytoyourhost.pem" \
59+
-e"ansible_user=ec2-user" \
60+
-e"ocp_username=${OCP_USERNAME}" \
61+
-e"ocp_workload=${WORKLOAD}" \
62+
-e"guid=${GUID}" \
63+
-e"ACTION=remove"
64+
----
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
- name: Run workload
3+
block:
4+
- name: Running Pre Workload Tasks
5+
include_tasks:
6+
file: pre_workload.yaml
7+
apply:
8+
become: "{{ become_override | bool }}"
9+
10+
- name: Running Workload Tasks
11+
include_tasks:
12+
file: workload.yaml
13+
apply:
14+
become: "{{ become_override | bool }}"
15+
when: ACTION == "create" or ACTION == "provision"
16+
17+
- name: Running Post Workload Tasks
18+
include_tasks:
19+
file: post_workload.yaml
20+
apply:
21+
become: "{{ become_override | bool }}"
22+
when: ACTION == "create" or ACTION == "provision"
23+
24+
- name: Running Workload removal Tasks
25+
include_tasks:
26+
file: remove_workload.yaml
27+
apply:
28+
become: "{{ become_override | bool }}"
29+
when: ACTION == "destroy" or ACTION == "remove"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
# Implement your Post Workload deployment tasks here
3+
# --------------------------------------------------
4+
5+
#
6+
#
7+
#
8+
9+
# Leave these as the last tasks in the playbook
10+
# ---------------------------------------------
11+
12+
# For deployment onto a dedicated cluster (as part of the
13+
# cluster deployment) set workload_shared_deployment to False
14+
# This is the default so it does not have to be set explicitely
15+
- name: post_workload tasks complete
16+
debug:
17+
msg: "Post-Workload tasks completed successfully."
18+
when:
19+
- not silent|bool
20+
- not workload_shared_deployment|default(False)
21+
22+
# For RHPDS deployment (onto a shared cluster) set
23+
# workload_shared_deployment to True
24+
# (in the deploy script or AgnosticV configuration)
25+
- name: post_workload tasks complete
26+
debug:
27+
msg: "Post-Software checks completed successfully"
28+
when:
29+
- not silent|bool
30+
- workload_shared_deployment|default(False)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
# Implement your Pre Workload deployment tasks here
3+
# -------------------------------------------------
4+
5+
- name: Set state
6+
set_fact:
7+
state: present
8+
when: not ocp4_workload_argocd_bootstrap_workload_destroy|bool
9+
10+
- name: Set state
11+
set_fact:
12+
state: absent
13+
when: ocp4_workload_argocd_bootstrap_workload_destroy|bool
14+
15+
# Leave these as the last tasks in the playbook
16+
# ---------------------------------------------
17+
18+
# For deployment onto a dedicated cluster (as part of the
19+
# cluster deployment) set workload_shared_deployment to False
20+
# This is the default so it does not have to be set explicitely
21+
- name: pre_workload tasks complete
22+
debug:
23+
msg: "Pre-Workload tasks completed successfully."
24+
when:
25+
- not silent|bool
26+
- not workload_shared_deployment|default(False)
27+
28+
# For RHPDS deployment (onto a shared cluster) set
29+
# workload_shared_deployment to True
30+
# (in the deploy script or AgnosticV configuration)
31+
- name: pre_workload tasks complete
32+
debug:
33+
msg: "Pre-Software checks completed successfully"
34+
when:
35+
- not silent|bool
36+
- workload_shared_deployment|default(False)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
# Implement your Workload removal tasks here
3+
- name: "Removing workload"
4+
include_tasks: "{{ item }}"
5+
with_items:
6+
- "./pre_workload.yaml"
7+
- "./workload.yaml"
8+
- "./post_workload.yaml"
9+
vars:
10+
ocp4_workload_argocd_bootstrap_workload_destroy: true
11+
12+
# Leave this as the last task in the playbook.
13+
- name: remove_workload tasks complete
14+
debug:
15+
msg: "Remove Workload tasks completed successfully."
16+
when: not silent|bool
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
- name: Clone the Lab repo
3+
git:
4+
repo: "{{ ocp4_workload_argocd_bootstrap_repo_url }}"
5+
dest: "/tmp/ocp4_workload_argocd_bootstrap_repo"
6+
version: "{{ ocp4_workload_argocd_bootstrap_branch }}"
7+
register: git_clone
8+
9+
- name: Apply the ApplicationSet YAML file
10+
command: "oc apply -f /tmp/ocp4_workload_argocd_bootstrap_repo/{{ ocp4_workload_argocd_bootstrap_yaml_file_path }}"
11+
when: git_clone.changed
12+
13+
# Leave this as the last task in the playbook.
14+
- name: workload tasks complete
15+
debug:
16+
msg: "Workload Tasks completed successfully."
17+
when: not silent|bool

0 commit comments

Comments
 (0)