# Need help with ansible playbook

**URL:** <https://forum.ansible.com/t/need-help-with-ansible-playbook/37553>\
**Category:** Ansible Project\
**Created:** [January 16, 2023, 6:35pm UTC](https://forum.ansible.com/t/need-help-with-ansible-playbook/37553 "2023-01-16T18:35:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shivani\_Arora](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Shivani\_Arora](https://forum.ansible.com/u/Shivani_Arora)\
**Post date:** [January 16, 2023, 6:35pm UTC](https://forum.ansible.com/t/need-help-with-ansible-playbook/37553/1 "2023-01-16T18:35:13Z")

</div>

Hi All,

I need help with writing an ansible playbook, where it loops over a few pods and checks if any pod is not running, does a describe on it, and prints the events (we get when we describe pods).

I’m stuck on the 2nd task here, where I can fetch ‘stdout’ but cannot filter the pod name from stdout. Please suggest how I can implement this.

I’m passing services\_to\_upgrade as an argument while running the playbook.

- name: Get pod information  
command: “kubectl get pods -l app={{ item }} -o json”  
register: pods\_info  
with\_items: “{{ services\_to\_upgrade.keys() }}”

- name: Print pod info  
set\_fact:  
pod\_name: “{{ pods\_info.results| json\_query(‘[\*].stdout’) }}”

I am looking forward to any suggestions.

Thanks

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [January 16, 2023, 8:13pm UTC](https://forum.ansible.com/t/need-help-with-ansible-playbook/37553/2 "2023-01-16T20:13:58Z")

</div>

Impossible without knowing what your variables look like. Provide those and we may be able to help

---

<div class="post-metadata">

**Author:** ![Shivani\_Arora](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Shivani\_Arora](https://forum.ansible.com/u/Shivani_Arora)\
**Post date:** [January 17, 2023, 5:22am UTC](https://forum.ansible.com/t/need-help-with-ansible-playbook/37553/3 "2023-01-17T05:22:02Z")

</div>

Thanks for replying.

This is how I’m passing the variables -

ansible-playbook --extra-vars “{‘services\_to\_upgrade’:{‘hedwig’:‘1.0.9-63’,‘venus’:‘1.0.11-2198’}}”

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [January 17, 2023, 6:07pm UTC](https://forum.ansible.com/t/need-help-with-ansible-playbook/37553/4 "2023-01-17T18:07:20Z")

</div>

Try to remove the \* from [\*] and the square brackets from stdout ( change ‘stdout’ becomes ‘stdout’ ). This will give you all of list of stdout strings. If you the individual lines of stdout then use stdout\_lines.

> set\_fact:  
> pod\_name: “{{ pods\_info.results | json\_query(‘.stdout’) }}”

Walter
