Skip to content

Commit

Permalink
Add OpenShift object removal role and playbooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfilipcz committed Sep 20, 2021
1 parent d84a5ab commit dddd270
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 7 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

14 changes: 7 additions & 7 deletions roles/ansible/tower/manage-schedules/templates/schedule.j2
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"rrule": "{{ schedule.rrule }}",
"name": "{{ schedule.name }}",
"description": "{{ schedule.description | default('') }}",
"extra_data": {{ schedule.extra_data | default("{}") | to_json }},
"inventory": "{{ schedule.inventory | default() }}",
"scm_branch": "{{ schedule.scm_branch | default('') }}",
"description": "{{ schedule.description }}",
"extra_data": {{ schedule.extra_data | to_json }},
"inventory": "{{ schedule.inventory }}",
"scm_branch": "{{ schedule.scm_branch }}",
"job_type": null,
"job_tags": "",
"skip_tags": "",
"limit": "{{ schedule.limit | default('') }}",
"limit": "{{ schedule.limit }}",
"diff_mode": null,
"verbosity": null,
"unified_job_template": "{{ unified_job_template_id | default('') }}",
"enabled": {{ schedule.enabled | default(true)| bool | lower }}
"unified_job_template": "{{ unified_job_template_id }}",
"enabled": {{ schedule.enabled | default(false) | bool | lower }}
}
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 dddd270

Please sign in to comment.