# Need guidance on how to develop ansible playbook for ocp pod health checks

**URL:** <https://forum.ansible.com/t/need-guidance-on-how-to-develop-ansible-playbook-for-ocp-pod-health-checks/40692>\
**Category:** Get Help\
**Created:** [February 28, 2025, 4:52am UTC](https://forum.ansible.com/t/need-guidance-on-how-to-develop-ansible-playbook-for-ocp-pod-health-checks/40692 "2025-02-28T04:52:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siveera](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@Siveera](https://forum.ansible.com/u/Siveera)\
**Post date:** [February 28, 2025, 4:52am UTC](https://forum.ansible.com/t/need-guidance-on-how-to-develop-ansible-playbook-for-ocp-pod-health-checks/40692/1 "2025-02-28T04:52:40Z")

</div>

I’m new to OCP. I got a task to develop playbook for health check.

Shared few ocp pod health check commands to execute in playbook.

Need help how to develop the playbook

---

<div class="post-metadata">

**Author:** ![hugonz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hugonz/32/503_2.png) [@hugonz](https://forum.ansible.com/u/hugonz)\
**Post date:** [February 28, 2025, 5:43am UTC](https://forum.ansible.com/t/need-guidance-on-how-to-develop-ansible-playbook-for-ocp-pod-health-checks/40692/2 "2025-02-28T05:43:13Z")

</div>

Can you post more information on what tasks you want to run on the pods?

In any case, the `kubernetes.core.k8s_exec` [kubernetes.core.k8s\_exec module – Execute command in Pod — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_exec_module.html) allows you to run commands on existing pods. You can select which pods are your target using `kubernetes.core.k8s_info`

Do you want to run commands for health checks inside pods, say, the etcd pods?

---

<div class="post-metadata">

**Author:** ![Siveera](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@Siveera](https://forum.ansible.com/u/Siveera)\
**Post date:** [February 28, 2025, 10:07am UTC](https://forum.ansible.com/t/need-guidance-on-how-to-develop-ansible-playbook-for-ocp-pod-health-checks/40692/3 "2025-02-28T10:07:30Z")

</div>

I want to develop playbook for health check report.  
Cluster health commands should be run via automated ansible playbook.  
For eg,  
oc get pods -n openshift  
Like above commands should be run via ansible playbook

---

<div class="post-metadata">

**Author:** ![hugonz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hugonz/32/503_2.png) [@hugonz](https://forum.ansible.com/u/hugonz)\
**Post date:** [February 28, 2025, 5:21pm UTC](https://forum.ansible.com/t/need-guidance-on-how-to-develop-ansible-playbook-for-ocp-pod-health-checks/40692/4 "2025-02-28T17:21:54Z")

</div>

If you’re new to developing playbooks, take a look at this post in the same forum: [Getting Started with Ansible - Resources](https://forum.ansible.com/t/getting-started-with-ansible-resources/1926) You need to understand basics like tasks before you can write the playbook.

That being said, if there’s a module, you should try to use the module instead of having Ansible run the command. Instead of trying to run `oc get pods -n openshift`, use the module as shown below to get the same effect.

```yaml
- name: Get OpenShift Pods
  hosts: localhost
  gather_facts: no
  environment:
    K8S_AUTH_HOST: 'http://...'
    K8S_AUTH_API_KEY: <your api key>
  tasks:
    - name: Retrieve pods in OpenShift namespace
      kubernetes.core.k8s_info:
        kind: Pod
        namespace: openshift
      register: openshift_pods

    - name: Display returned info
      debug:
        msg: "{{ openshift_pods.resources }}"

```
