Skip to content

Commit

Permalink
Add OpenShift object manage role and playbooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfilipcz committed Dec 3, 2021
1 parent 87a8297 commit 27c99d8
Show file tree
Hide file tree
Showing 13 changed files with 151 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-manage-objects-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

5 changes: 5 additions & 0 deletions playbooks/openshift-manage-objects-via-exec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

- hosts: openshift_api
roles:
- role: openshift/manage-objects-via-exec
54 changes: 54 additions & 0 deletions roles/openshift/manage-objects-via-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
manage-objects-via-api
========================

This role is used to manage OpenShift objects via OpenShift API. Role is expected to be run on Ansible Host running within OpenShift cluster, that's a target for object management

## Requirements

- Ansible Host running within targetted OpenShift cluster


## Role Variables


| Variable | Description | Required | Defaults |
|:---------|:------------|:---------|:---------|
|openshift_manage_objects.name|Name of OpenShift object to be processed|yes||
|openshift_manage_objects.kind|Kind of object to be processed|yes||
|openshift_manage_objects.namespace|OpenShift Namespace in which object to be processed resides|yes||
|openshift_manage_objects.api_version|API version used for object|yes||
|openshift_manage_objects.state|Desired state of OpenShift object|no|"present"|


## Example Inventory

```yaml
---
openshift_manage_objects:
- name: argo-app-abc
kind: Application
namespace: argocd-apps
api_version: argoproj.io/v1alpha1
state: absent
```
## Example Playbook
```yaml
---

- hosts: openshift-api
roles:
- role: manage-openshift-objects-via-api
```
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/manage-objects-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/manage-objects-via-api/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

- import_tasks: manage_objects.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 }}"
56 changes: 56 additions & 0 deletions roles/openshift/manage-objects-via-exec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
manage-openshift-object-via-exec
========================

This role is used to manage OpenShift object with a help of oc or kubectl. Role is expected to be run on Ansible Host running within OpenShift cluster, that's a target for object action

## Requirements

- Ansible Host running within targetted OpenShift cluster
- OC or kubectl installed on Ansible Host

## Role Variables


| Variable | Description | Required | Defaults |
|:---------|:------------|:---------|:---------|
|openshift_manage_objects.name|Name of OpenShift object to be removed|yes||
|openshift_manage_objects.kind|Kind of object to be removed|yes||
|openshift_manage_objects.executable|Name of executable to be used for operation(oc/kubectl)|yes||
|openshift_manage_objects.namespace|OpenShift Namespace in which object to be removed resides|yes||
|openshift_manage_objects.api_version|API version used for object|yes||
|openshift_manage_objects.action| OC/Kubectl action to be executed on specified object|yes||


## Example Inventory

```yaml
---
openshift_manage_objects:
- name: argo-app-abc
executable: oc
kind: Application
namespace: argocd-apps
api_version: argoproj.io/v1alpha1
action: delete
```
## Example Playbook
```yaml
---

- hosts: openshift-api
roles:
- role: manage-openshift-objects-via-exec
```
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/manage-objects-via-exec/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
3 changes: 3 additions & 0 deletions roles/openshift/manage-objects-via-exec/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

- import_tasks: manage_objects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Manage OpenShift objects with Executable
shell:
cmd: "{{item.executable}} {{ item.action }} {{ item.kind }}/{{ item.name }} -n {{ item.namespace }}"
loop: "{{ openshift_manage_objects }}"

0 comments on commit 27c99d8

Please sign in to comment.