OpenShift - Delete Pods using Ansible

by
Jeremy Canfield |
Updated: October 03 2024
| OpenShift articles
This assumes you are already familiar with logging in and logging out of OpenShift using Ansible. If not, check out my article FreeKB - OpenShift - Log into OpenShift using Ansible community.okd.openshift_auth.
Here is an example of how to delete the pod named my_pod in the project/namespace my_project using Ansible kubernetes.core.k8s.
---
- hosts: localhost
module_defaults:
group/community.okd.okd:
host: https://api.lab001.op.thrivent.com:6443
validate_certs: False
tasks:
- block:
- name: login
community.okd.openshift_auth:
username: john.doe
password: itsasecret
register: openshift_auth_results
- name: delete the pod named 'my_pod' in project/namespace my_project
kubernetes.core.k8s:
kind: Pod
namespace: my_project
name: my_pod
state: absent
always:
- name: logout
community.okd.openshift_auth:
state: absent
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
...
Did you find this article helpful?
If so, consider buying me a coffee over at