Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenShift Object Manage roles and playbooks #646

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}"