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
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
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 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?
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
If you’re new to developing playbooks, take a look at this post in the same forum: Getting Started with Ansible - Resources 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.
- 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 }}"