# Printing only stdout\_lines with command + with\_items

**URL:** <https://forum.ansible.com/t/printing-only-stdout-lines-with-command-with-items/32043>\
**Category:** Ansible Project\
**Created:** [January 24, 2020, 12:03am UTC](https://forum.ansible.com/t/printing-only-stdout-lines-with-command-with-items/32043 "2020-01-24T00:03:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_Yue](https://avatars.discourse-cdn.com/v4/letter/n/bcef8e/32.png) [@Nicholas\_Yue](https://forum.ansible.com/u/Nicholas_Yue)\
**Post date:** [January 24, 2020, 12:03am UTC](https://forum.ansible.com/t/printing-only-stdout-lines-with-command-with-items/32043/1 "2020-01-24T00:03:36Z")

</div>

Hi,

I have the following ansible script

$ cat generated-head-node.yaml

- hosts: all  
tasks:
- name: Run multiple commands  
command: “{{item}}”  
with\_items:
- pwd
- ls  
register: out
- debug: msg=“{{ item.stdout\_lines }}”  
with\_items: “{{ out.results }}”

I am unable to print out just the output results in stdout\_lines, it prints out other information which I’d like to suppress

How do I achieve that ?

PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [192.168.8.45]

TASK [Run multiple commands] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [192.168.8.45] =\> (item=pwd)  
changed: [192.168.8.45] =\> (item=ls)

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [192.168.8.45] =\> (item={‘changed’: True, ‘end’: ‘2020-01-23 17:58:52.021083’, ‘stdout’: ‘/home/nyue’, ‘cmd’: [‘pwd’], ‘rc’: 0, ‘start’: ‘2020-01-23 17:58:52.009380’, ‘stderr’: ‘’, ‘delta’: ‘0:00:00.011703’, ‘invocation’: {‘module\_args’: {‘creates’: None, ‘executable’: None, ‘\_uses\_shell’: False, ‘strip\_empty\_ends’: True, ‘\_raw\_params’: ‘pwd’, ‘removes’: None, ‘argv’: None, ‘warn’: True, ‘chdir’: None, ‘stdin\_add\_newline’: True, ‘stdin’: None}}, ‘stdout\_lines’: [‘/home/nyue’], ‘stderr\_lines’: , ‘failed’: False, ‘item’: ‘pwd’, ‘ansible\_loop\_var’: ‘item’}) =\> {  
“msg”: [  
“/home/nyue”  
]  
}  
ok: [192.168.8.45] =\> (item={‘changed’: True, ‘end’: ‘2020-01-23 17:58:53.644286’, ‘stdout’: ‘Desktop\nDocuments\nDownloads\nMusic\nPictures\nPublic\nTemplates\nVideos’, ‘cmd’: [‘ls’], ‘rc’: 0, ‘start’: ‘2020-01-23 17:58:53.638312’, ‘stderr’: ‘’, ‘delta’: ‘0:00:00.005974’, ‘invocation’: {‘module\_args’: {‘creates’: None, ‘executable’: None, ‘\_uses\_shell’: False, ‘strip\_empty\_ends’: True, ‘\_raw\_params’: ‘ls’, ‘removes’: None, ‘argv’: None, ‘warn’: True, ‘chdir’: None, ‘stdin\_add\_newline’: True, ‘stdin’: None}}, ‘stdout\_lines’: [‘Desktop’, ‘Documents’, ‘Downloads’, ‘Music’, ‘Pictures’, ‘Public’, ‘Templates’, ‘Videos’], ‘stderr\_lines’: , ‘failed’: False, ‘item’: ‘ls’, ‘ansible\_loop\_var’: ‘item’}) =\> {  
“msg”: [  
“Desktop”,  
“Documents”,  
“Downloads”,  
“Music”,  
“Pictures”,  
“Public”,  
“Templates”,  
“Videos”  
]  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
192.168.8.45 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

Cheers

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [January 24, 2020, 5:09am UTC](https://forum.ansible.com/t/printing-only-stdout-lines-with-command-with-items/32043/2 "2020-01-24T05:09:58Z")

</div>

Use 'loop\_control' and declare what 'label' shall be printed. For example

&nbsp;&nbsp;&nbsp;&nbsp;- debug: msg="{{ item.stdout\_lines }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ out.results }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop\_control:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label: "{{ item.cmd }}"

HTH,

&nbsp;&nbsp;-vlado
