# Clean up debug output

**URL:** <https://forum.ansible.com/t/clean-up-debug-output/36150>\
**Category:** Ansible Project\
**Created:** [December 23, 2021, 8:52am UTC](https://forum.ansible.com/t/clean-up-debug-output/36150 "2021-12-23T08:52:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lee](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lee/32/4857_2.png) [@lee](https://forum.ansible.com/u/lee)\
**Post date:** [December 23, 2021, 8:52am UTC](https://forum.ansible.com/t/clean-up-debug-output/36150/1 "2021-12-23T08:52:00Z")

</div>

Hi,

I have a small Ansible playbook.

-----------------%\<-----------------

- hosts: localhost  
tasks:

- name: Populate service facts  
ansible.builtin.service\_facts:

- name: Print service facts  
loop:

- postfix

- rsyslog

- sshd  
ansible.builtin.debug:  
var: ansible\_facts.services[‘{{ item }}.service’][‘state’]  
-----------------%\<-----------------

The output is

-----------------%\<-----------------

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

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

TASK [Populate service facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK [Print service facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> (item=postfix) =\> {  
“ansible\_facts.services[‘postfix.service’][‘state’]”: “running”,  
“ansible\_loop\_var”: “item”,  
“item”: “postfix”  
}  
ok: [localhost] =\> (item=rsyslog) =\> {  
“ansible\_facts.services[‘rsyslog.service’][‘state’]”: “running”,  
“ansible\_loop\_var”: “item”,  
“item”: “rsyslog”  
}  
ok: [localhost] =\> (item=sshd) =\> {  
“ansible\_facts.services[‘sshd.service’][‘state’]”: “running”,  
“ansible\_loop\_var”: “item”,  
“item”: “sshd”  
}

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

-----------------%\<-----------------

What I want is

TASK [Print service facts]

should print only

“ansible\_facts.services[‘rsyslog.service’][‘state’]”: “running”

The other three should be hidden.

Any easy trick for this ?

Thanks

---

<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:** [December 23, 2021, 10:35am UTC](https://forum.ansible.com/t/clean-up-debug-output/36150/2 "2021-12-23T10:35:56Z")

</div>

Try

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Print service facts  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ansible.builtin.debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: '{{ \_sr }}: {{ \_st }}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- postfix  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- rsyslog  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- sshd  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\_sr: 'ansible\_facts.services["{{ item }}.service"]["state"]'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\_st: '{{ ansible\_facts.services[item ~ ".service"].state }}'

The single/double quotes of the results are reversed. If this is a  
problem you'll have to escape them.

ok: [localhost] =\> (item=sshd) =\>  
&nbsp;&nbsp;msg: 'ansible\_facts.services["sshd.service"]["state"]: active'

---

<div class="post-metadata">

**Author:** ![lee](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lee/32/4857_2.png) [@lee](https://forum.ansible.com/u/lee)\
**Post date:** [December 23, 2021, 11:59am UTC](https://forum.ansible.com/t/clean-up-debug-output/36150/3 "2021-12-23T11:59:00Z")

</div>

Thanks a lot, Vladimir  
That works.

Thanks
