Ansible iterate from a list

0 votes

My ansible code is this one:

- name: Search for all running pods from file ./data/kubernetes/pods-status
  shell: | 
    cat ./data/kubernetes/pods-status
  register: pods
    
- name: Pods name
  set_fact:
    podnames: "{{ pods.stdout|from_json|json_query(names) }}"
    podkind: "{{ pods.stdout|from_json|json_query(kind) }}"
  vars:
    names: 'items[*].metadata.name'
    kind: 'items[*].kind'

- name: Copy pods information to local file
  local_action: 
  module: copy
    dest: "./data/kubernetes/mainpod.json"
    #content: "{{ podsjson | to_json }} "
    content: "{{ [{'val': item }] }}"
  loop: "{{  podnames }}"

I'm expecting to have the following file:

{
  "items": {
    "name": "backend-99fb66465-2lxwp",
    "namespace":"testingspace" 
    },
    {
    "name": "backend-99fb66465-2lxwp",
    "namespace": "testingspace"
    }
  }
} 

But so far i just have this one:

[{"val": "backup-mysqldump-27875520-d26j4"}]
Jan 12, 2023 in DevOps on Cloud by David
• 220 points

edited 5 days ago 19 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP