# List of running processes form multiple linux hosts using with\_items

**URL:** <https://forum.ansible.com/t/list-of-running-processes-form-multiple-linux-hosts-using-with-items/27238>\
**Category:** Ansible Project\
**Created:** [April 11, 2018, 8:12am UTC](https://forum.ansible.com/t/list-of-running-processes-form-multiple-linux-hosts-using-with-items/27238 "2018-04-11T08:12:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smitconsultant2017](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@smitconsultant2017](https://forum.ansible.com/u/smitconsultant2017)\
**Post date:** [April 11, 2018, 8:12am UTC](https://forum.ansible.com/t/list-of-running-processes-form-multiple-linux-hosts-using-with-items/27238/1 "2018-04-11T08:12:44Z")

</div>

Hi  
I am trying to achieve all running processes on our linux machines via ansible and get output in a file along with each host name and processes. I have made below playbook but not getting to the point how to get list of processes for each host one by one and store in a file. Can anyone please help with the code how can I achieve this? I am using with\_items with list of hosts which is coming from inventory group hostlist. many thanks

---

<div class="post-metadata">

**Author:** ![Bishwajit\_Samanta](https://avatars.discourse-cdn.com/v4/letter/b/8e7dd6/32.png) [@Bishwajit\_Samanta](https://forum.ansible.com/u/Bishwajit_Samanta)\
**Post date:** [April 12, 2018, 7:09am UTC](https://forum.ansible.com/t/list-of-running-processes-form-multiple-linux-hosts-using-with-items/27238/2 "2018-04-12T07:09:41Z")

</div>

I just changed the host as devops

---

<div class="post-metadata">

**Author:** ![smitconsultant2017](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@smitconsultant2017](https://forum.ansible.com/u/smitconsultant2017)\
**Post date:** [April 13, 2018, 8:11am UTC](https://forum.ansible.com/t/list-of-running-processes-form-multiple-linux-hosts-using-with-items/27238/3 "2018-04-13T08:11:21Z")

</div>

HI Bishwajit Samanta

Thanks. It is creating file for each hostname but data is not in readable format. Are you able to do favor little more, how to get the data in each file as orignal form like as processes list show on linux machine? I was initially thinking to get output from all hosts in one file and somehow get processes list along with hostname one by one. But this can work as well. Many Thanks.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 13, 2018, 3:14pm UTC](https://forum.ansible.com/t/list-of-running-processes-form-multiple-linux-hosts-using-with-items/27238/4 "2018-04-13T15:14:13Z")

</div>

> Thanks. It is creating file for each hostname but data is not in readable  
> format. Are you able to do favor little more, how to get the data in each  
> file as orignal form like as processes list show on linux machine?

Replace {{ output }} with {{ output.stdout }}

> I was  
> initially thinking to get output from all hosts in one file and somehow get  
> processes list along with hostname one by one. But this can work as well.

To do that you need to use jinja template, something like this should work.

&nbsp;&nbsp;- name: Getting some details of systems  
&nbsp;&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% for i in ansible\_play\_hosts %}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Output for host {{ i }}:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ hostvars[i].output.stdout }}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% endfor %}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /my/file  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate: localhost
