# Ansible with registers using loop

**URL:** <https://forum.ansible.com/t/ansible-with-registers-using-loop/18811>\
**Category:** Ansible Project\
**Created:** [July 21, 2015, 5:58am UTC](https://forum.ansible.com/t/ansible-with-registers-using-loop/18811 "2015-07-21T05:58:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavan\_reddy](https://avatars.discourse-cdn.com/v4/letter/p/9dc877/32.png) [@pavan\_reddy](https://forum.ansible.com/u/pavan_reddy)\
**Post date:** [July 21, 2015, 5:58am UTC](https://forum.ansible.com/t/ansible-with-registers-using-loop/18811/1 "2015-07-21T05:58:16Z")

</div>

Hi,

below is the playbook.i wanna multiple commands in a single task using loop (with\_items) and copy the stdout of each loop for every hosts in a file.

---

<div class="post-metadata">

**Author:** ![Larry\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@Larry\_Smith1](https://forum.ansible.com/u/Larry_Smith1)\
**Post date:** [July 22, 2015, 8:56pm UTC](https://forum.ansible.com/t/ansible-with-registers-using-loop/18811/2 "2015-07-22T20:56:16Z")

</div>

Based on what you are looking for this should do it for you.

> * * *
> 
> - hosts: all  
> gather\_facts: true  
> remote\_user: remote  
> sudo: true  
> tasks:
> - name: capture linux\_os  
> shell: “{{ item }}”  
> register: linux\_os  
> with\_items:
> - ‘uname -a’
> - ‘cat /etc/resolv.conf’
> - name: creating inventory hosts  
> file: path=“{{ inventory\_hostname }}”.txt state=touch  
> delegate\_to: localhost  
> sudo: false
> - name: results  
> lineinfile: dest=“{{ inventory\_hostname }}”.txt line=“{{ item.stdout }}”  
> delegate\_to: localhost  
> sudo: false  
> with\_items: linux\_os.results

resulting in.
