Skip to content

Commit

Permalink
Add OpenShift object removal role and playbooks.
Browse files Browse the repository at this point in the history
Templates update

UJID change

Modified role to support lists of objects

Fixed wrong var name

Added new role to delete objects through oc

Updated playbook

W sumie nic ciekawego
  • Loading branch information
jfilipcz committed Sep 19, 2021
1 parent d84a5ab commit 855edf0
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions inventory/openshift_api/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
4 changes: 4 additions & 0 deletions inventory/openshift_api/host_vars/localhost.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

ansible_connection: local

3 changes: 3 additions & 0 deletions inventory/openshift_api/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[openshift_api]
localhost

6 changes: 6 additions & 0 deletions playbooks/openshift-remove-object-via-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

- hosts: openshift_api
roles:
- role: openshift/remove-object-via-api

6 changes: 6 additions & 0 deletions playbooks/openshift-remove-object-via-oc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

- hosts: openshift_api
roles:
- role: openshift/remove-object-via-oc

52 changes: 52 additions & 0 deletions roles/openshift/remove-object-via-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
remove-openshift-object-via-api
========================

This role is used to remove OpenShift object via OpenShift API. 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 |
|:---------|:------------|:---------|:---------|
|openshift_remove_object.name|Name of OpenShift object to be removed|yes||
|openshift_remove_objects.kind|Kind of object to be removed|yes||
|openshift_remove_objects.namespace|OpenShift Namespace in which object to be removed resides|yes||
|openshift_remove_objects.api_version|API version used for object|yes||


## Example Inventory

```yaml
---
openshift_remove_objects:
- name: argo-app-abc
kind: Application
namespace: argocd-apps
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.
1 change: 1 addition & 0 deletions roles/openshift/remove-object-via-api/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
3 changes: 3 additions & 0 deletions roles/openshift/remove-object-via-api/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

- import_tasks: remove_object.yml
9 changes: 9 additions & 0 deletions roles/openshift/remove-object-via-api/tasks/remove_object.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Remove OpenShift object via OpenShift API
k8s:
state: absent
name: "{{ item.name }}"
api_version: "{{ item.api_version }}"
kind: "{{ item.kind }}"
namespace: "{{ item.namespace }}"
loop: "{{ openshift_remove_objects }}"
52 changes: 52 additions & 0 deletions roles/openshift/remove-object-via-oc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
remove-openshift-object-via-oc
========================

This role is used to remove OpenShift object with a help of oc. 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
- OC installed on Ansible Host

## Role Variables


| Variable | Description | Required | Defaults |
|:---------|:------------|:---------|:---------|
|openshift_remove_object.name|Name of OpenShift object to be removed|yes||
|openshift_remove_objects.kind|Kind of object to be removed|yes||
|openshift_remove_objects.namespace|OpenShift Namespace in which object to be removed resides|yes||
|openshift_remove_objects.api_version|API version used for object|yes||


## Example Inventory

```yaml
---
openshift_remove_objects:
- name: argo-app-abc
kind: Application
namespace: argocd-apps
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.
1 change: 1 addition & 0 deletions roles/openshift/remove-object-via-oc/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
3 changes: 3 additions & 0 deletions roles/openshift/remove-object-via-oc/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

- import_tasks: remove_object.yml
5 changes: 5 additions & 0 deletions roles/openshift/remove-object-via-oc/tasks/remove_object.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Remove OpenShift object with OC
shell:
cmd: "oc delete {{ item.kind }}/{{ item.name }} -n {{ item.namespace }}"
loop: "{{ openshift_remove_objects }}"

0 comments on commit 855edf0

Please sign in to comment.