From 339f6d19011fc6db2c274ecb9b432e9404dd047a Mon Sep 17 00:00:00 2001 From: Jakub Filipczak Date: Tue, 7 Sep 2021 13:19:53 +0200 Subject: [PATCH] Initial commit for OpenShift Object Remove role --- inventory/openshift-api/group_vars/all.yml | 1 + .../openshift-api/host_vars/localhost.yml | 4 ++ inventory/openshift-api/hosts | 3 ++ playbooks/openshift-remove-object.yml | 6 +++ roles/openshift/remove-object/README.md | 54 +++++++++++++++++++ .../openshift/remove-object/defaults/main.yml | 1 + roles/openshift/remove-object/tasks/main.yml | 3 ++ .../remove-object/tasks/remove_object.yml | 8 +++ 8 files changed, 80 insertions(+) create mode 100644 inventory/openshift-api/group_vars/all.yml create mode 100644 inventory/openshift-api/host_vars/localhost.yml create mode 100644 inventory/openshift-api/hosts create mode 100644 playbooks/openshift-remove-object.yml create mode 100644 roles/openshift/remove-object/README.md create mode 100644 roles/openshift/remove-object/defaults/main.yml create mode 100644 roles/openshift/remove-object/tasks/main.yml create mode 100644 roles/openshift/remove-object/tasks/remove_object.yml diff --git a/inventory/openshift-api/group_vars/all.yml b/inventory/openshift-api/group_vars/all.yml new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/inventory/openshift-api/group_vars/all.yml @@ -0,0 +1 @@ +--- diff --git a/inventory/openshift-api/host_vars/localhost.yml b/inventory/openshift-api/host_vars/localhost.yml new file mode 100644 index 000000000..d9bda51a8 --- /dev/null +++ b/inventory/openshift-api/host_vars/localhost.yml @@ -0,0 +1,4 @@ +--- + +ansible_connection: local + diff --git a/inventory/openshift-api/hosts b/inventory/openshift-api/hosts new file mode 100644 index 000000000..9bdf5f5f6 --- /dev/null +++ b/inventory/openshift-api/hosts @@ -0,0 +1,3 @@ +[openshift_api] +localhost + diff --git a/playbooks/openshift-remove-object.yml b/playbooks/openshift-remove-object.yml new file mode 100644 index 000000000..a7c0e4454 --- /dev/null +++ b/playbooks/openshift-remove-object.yml @@ -0,0 +1,6 @@ +--- + +- hosts: openshift_api + roles: + - role: openshift/remove-object + diff --git a/roles/openshift/remove-object/README.md b/roles/openshift/remove-object/README.md new file mode 100644 index 000000000..bef416fe2 --- /dev/null +++ b/roles/openshift/remove-object/README.md @@ -0,0 +1,54 @@ +remove-openshift-object +======================== + +This role is used to remove specific OpenShift object. Role is expected to be run on Ansible Host running within OpenShift cluster, that's a target for object removal + +## Requirements + + - Ansible Host running within targetted OpenShift cluster + + +## Role Variables + + +| Variable | Description | Required | Defaults | +|:---------|:------------|:---------|:---------| +|ocp_object_name|Name of OpenShift object to be removed|yes|| +|ocp_object_kind|Kind of object to be removed|yes|| +|ocp_object_namespace|OpenShift Namespace in which object to be removed resides|yes|| +|ocp_object_api_version|API version used for object|yes|| + + + + +## Example Inventory + +```yaml +--- +ocp_object_name: argo-app-abc +ocp_object_kind: Application +ocp_object_namespace: argocd-apps +ocp_object_api_version: argoproj.io/v1alpha1 + +``` + +## Example Playbook + +```yaml +--- + +- hosts: openshift-api + roles: + - role: remove-openshift-object +``` + +License +------- + +Apache License 2.0 + + +Author Information +------------------ + +Red Hat Community of Practice & staff of the Red Hat Open Innovation Labs. diff --git a/roles/openshift/remove-object/defaults/main.yml b/roles/openshift/remove-object/defaults/main.yml new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/roles/openshift/remove-object/defaults/main.yml @@ -0,0 +1 @@ +--- diff --git a/roles/openshift/remove-object/tasks/main.yml b/roles/openshift/remove-object/tasks/main.yml new file mode 100644 index 000000000..2b7d24c74 --- /dev/null +++ b/roles/openshift/remove-object/tasks/main.yml @@ -0,0 +1,3 @@ +--- + +- import_tasks: remove_object.yml diff --git a/roles/openshift/remove-object/tasks/remove_object.yml b/roles/openshift/remove-object/tasks/remove_object.yml new file mode 100644 index 000000000..65469575b --- /dev/null +++ b/roles/openshift/remove-object/tasks/remove_object.yml @@ -0,0 +1,8 @@ +--- +- name: Remove OpenShift object + k8s: + state: absent + name: "{{ ocp_object_name }}" + api_version: "{{ ocp_object_api_version }}" + kind: "{{ ocp_object_kind }}" + namespace: "{{ ocp_object_namespace }}"