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 }}"