How get all the containers of a pod

67 views
Skip to first unread message

George Tsoumplekas

unread,
Mar 22, 2021, 7:14:01 AM3/22/21
to Ansible Development

 try to get all the containers that are included in a pod using ansible.. I have no experience in ansible and kubernetes. It is the first I have worked with ansible and kubernetes

I use an iteration through the pods to get name's of the containers that are include in a pod. I face two problems . The first is that when the script is called , I get an error that item is undefined . The second one is how I will get containers name, image version?

Below is the script

---

- name: Demmo

  k8s_info:

    kind: Pod

    namespace: '{{ meta.namespace }}'

  register: pod_list

# tasks file for configmap

- name: Get the  info from pod

  set_fact:

    podName : "{{ pod_list | json_query(query) }}"

  vars:

    query: 'resources[].{name: metadata.name}'


#use the info from podName and call again kubectl get

- name: Get the container  object 2

  k8s_info:

    kind: Pod

k8s_info    namespace: '{{ meta.namespace }}'

    name: "{{item.name}}"

    loop: "{{podName}}"

    loop_control:

      label: "{{ item.name }}"

  register: pod_list2



Reply all
Reply to author
Forward
0 new messages