# how to access debug  stdout variable

**URL:** <https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051>\
**Category:** Ansible Project\
**Created:** [April 3, 2019, 2:22pm UTC](https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051 "2019-04-03T14:22:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [April 3, 2019, 2:22pm UTC](https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051/1 "2019-04-03T14:22:32Z")

</div>

playbook:-

task:-

- name: Deploying PCC-test  
hosts: pulp  
gather\_facts: true  
vars\_files:
- /etc/ansible/inventories/group\_vars/common.yaml  
vars:
- rpmsearch: true
- rpmname:
- mobi-auth-manager-5.42.0-201903291228.ed4d6a0.noarch  
serial: 1  
any\_errors\_fatal: true  
roles:
- role: mobi\_ansible\_role\_pulp

Pulp.yaml:-

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 3, 2019, 2:29pm UTC](https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051/2 "2019-04-03T14:29:31Z")

</div>

> playbook:-  
> task:-  
> - name: Deploying PCC-test  
> hosts: pulp  
> gather\_facts: true  
> vars\_files:  
> - /etc/ansible/inventories/group\_vars/common.yaml  
> vars:  
> - rpmsearch: true  
> - rpmname:  
> - mobi-auth-manager-5.42.0-201903291228.ed4d6a0.noarch  
> serial: 1  
> any\_errors\_fatal: true  
> roles:  
> - role: mobi\_ansible\_role\_pulp
> 
> Pulp.yaml:-
> 
> ---  
> - name: Logging into pulp  
> shell: pulp-admin login -u admin -p admin  
> - name: searching the rpm into pulp repo  
> shell: pulp-admin rpm repo content rpm --repo-id=mobi-snapshots --match 'filename={{ item }}'  
> with\_items: "{{ rpmname | default() }}"  
> register: pulp  
> when: rpmsearch is defined  
> - debug:  
> var: pulp.results.stdout

Hello Kunalsing,

please try pulp.stdout instead.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Sebastian\_Meyer](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@Sebastian\_Meyer](https://forum.ansible.com/u/Sebastian_Meyer)\
**Post date:** [April 3, 2019, 2:30pm UTC](https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051/3 "2019-04-03T14:30:58Z")

</div>

You are using register with a loop. That means pulp.results is a list  
and there's an element for each item in that list.

You can access the stdout for the first item with pulp.results.0.stdout

Sebastian

---

<div class="post-metadata">

**Author:** ![Raghavendra\_Rao](https://avatars.discourse-cdn.com/v4/letter/r/c77e96/32.png) [@Raghavendra\_Rao](https://forum.ansible.com/u/Raghavendra_Rao)\
**Post date:** [April 3, 2019, 2:31pm UTC](https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051/4 "2019-04-03T14:31:20Z")

</div>

This should be  
var: pulp.stdout

-R.Rao

---

<div class="post-metadata">

**Author:** ![kunalsing\_thakur1](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@kunalsing\_thakur1](https://forum.ansible.com/u/kunalsing_thakur1)\
**Post date:** [April 3, 2019, 2:37pm UTC](https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051/5 "2019-04-03T14:37:35Z")

</div>

Thank You sebastian. Now i am able to print stdout using

pulp.results.0.stdout

---

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [April 3, 2019, 2:44pm UTC](https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051/6 "2019-04-03T14:44:30Z")

</div>

Hi sebastian,  
when i try to fail the task with this below condition i get the error in task

**failed\_when: pulp.results.0.stdout == “\e[0m”**

TASK [mobi\_ansible\_role\_pulp : searching the rpm into pulp repo] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /etc/ansible/roles/mobi\_ansible\_role\_pulp/tasks/pulp.yaml:4  
Wednesday 03 April 2019 14:40:58 +0000 (0:00:01.856) 0:00:06.231 \*\*\*\*\*\*\*  
fatal: [inplp01p2.infra.smf1.mobitv]: FAILED! =\>  
msg: ‘The conditional check ‘‘pulp.results.0.stdout == “\e[0m”’’ failed. The error was: error while evaluating conditional (pulp.results.0.stdout == “\e[0m”): ‘‘dict object’’ has no attribute ‘‘results’’’

---

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [April 3, 2019, 2:47pm UTC](https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051/7 "2019-04-03T14:47:51Z")

</div>

when i print the pulp.results.0.stdout it will give me following output:-  
TASK [mobi\_ansible\_role\_pulp : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /etc/ansible/roles/mobi\_ansible\_role\_pulp/tasks/pulp.yaml:9  
Wednesday 03 April 2019 14:46:40 +0000 (0:00:02.206) 0:00:09.036 \*\*\*\*\*\*\*  
ok: [inplp01p2.infra.smf1.mobitv] =\>  
pulp.results.0.stdout: “\e[0m”

which is blank so i want to failed this task?

---

<div class="post-metadata">

**Author:** ![Sebastian\_Meyer](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@Sebastian\_Meyer](https://forum.ansible.com/u/Sebastian_Meyer)\
**Post date:** [April 3, 2019, 2:47pm UTC](https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051/8 "2019-04-03T14:47:54Z")

</div>

> Hi sebastian,  
> when i try to fail the task with this below condition i get the error in  
> task
> 
> \*failed\_when: pulp.results.0.stdout == "\e[0m"\*
> 
> TASK [mobi\_ansible\_role\_pulp : searching the rpm into pulp repo]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> task path: /etc/ansible/roles/mobi\_ansible\_role\_pulp/tasks/pulp.yaml:4  
> Wednesday 03 April 2019 14:40:58 +0000 (0:00:01.856) 0:00:06.231  
> \*\*\*\*\*\*\*  
> fatal: [inplp01p2.infra.smf1.mobitv]: FAILED! =\>  
> &nbsp;&nbsp;msg: 'The conditional check ''pulp.results.0.stdout == "\e[0m"'' failed.  
> The error was: error while evaluating conditional (pulp.results.0.stdout ==  
> "\e[0m"): ''dict object'' has no attribute ''results'''

While you are in the loop you should be able to use just pulp.stdout,  
only afterwards the results are merged.

Sebastian

---

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [April 3, 2019, 4:02pm UTC](https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051/9 "2019-04-03T16:02:21Z")

</div>

Hi sebastian,

pulp.results.0.stdout give me output “\e[0m”

But when I try to access in failed\_when condition  
It is giving me below error.  
fatal: [node]: FAILED! =\>

msg: ‘The conditional check ‘‘pulp.results.0.stdout == “\e[0m”’’ failed. The error was: error while evaluating conditional (pulp.results.0.stdout == “\e[0m”): ‘‘dict object’’ has no attribute ‘‘results’’’

Looks like in faiked\_when condition it needs dictionary?

---

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [April 6, 2019, 10:09am UTC](https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051/10 "2019-04-06T10:09:10Z")

</div>

I was able to successfully do this task by following the instructions.  
Thanks for matt to give some logic.

- name: searching the rpm into {{ reponame }} repo  
shell: pulp-admin rpm repo content rpm --repo-id={{reponame}} --match ‘filename={{ item }}’  
loop: “{{ rpmname | default() }}”  
register: pulp  
when: search is defined  
failed\_when: pulp.stdout == “\u001b[0m”

Result:-  
TASK [mobi\_ansible\_role\_pulp : searching the rpm into infra] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /etc/ansible/roles/mobi\_ansible\_role\_pulp/tasks/pulp.yaml:5  
Saturday 06 April 2019 10:07:15 +0000 (0:00:02.298) 0:00:02.709 \*\*\*\*\*\*\*\*  
failed: [node] (item=GoIP-devel-1.6.11-201711302323.798cb6f.el7.centos.x86\_64.rpm) =\> changed=true  
cmd: pulp-admin rpm repo content rpm --repo-id=mobi-infra.smf1.mobitv --match ‘filename=GoIP-devel-1.6.11-201711302323.798cb6f.el7.centos.x86\_64.rpm’  
delta: ‘0:00:00.781775’  
end: ‘2019-04-06 10:07:17.178794’  
failed\_when\_result: true  
item: GoIP-devel-1.6.11-201711302323.798cb6f.el7.centos.x86\_64.rpm  
rc: 0  
start: ‘2019-04-06 10:07:16.397019’  
stderr: ‘’  
stderr\_lines:   
stdout: “\e[0m”  
stdout\_lines:

This issue is resolved now. 🙂

---

<div class="post-metadata">

**Author:** ![Melissa\_Liana](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@Melissa\_Liana](https://forum.ansible.com/u/Melissa_Liana)\
**Post date:** [April 8, 2019, 5:27am UTC](https://forum.ansible.com/t/how-to-access-debug-stdout-variable/30051/11 "2019-04-08T05:27:15Z")

</div>

Hi,

Instead of _stdout_, I would suggest using _stdout\_lines_. For multiline output this is much nicer, e.g.

```auto
- hosts: all
  tasks:
    - name: Run ls.sh and output "ls /"
      script: ls.sh
      register: out

    - debug: var=out.stdout_lines

```

gives

```auto
TASK: [debug var=out.stdout_lines] ******************************************** 
ok: [local] => {
    "var": {
        "out.stdout_lines": [
            "total 61", 
            "lrwxrwxrwx 1 root root 7 Feb 15 2015 bin -> usr/bin", 
            "drwxr-xr-x 6 root root 1024 Aug 24 22:08 boot", 
            "drwxr-xr-x 22 root root 3580 Sep 8 18:41 dev",  
            [...] 
            "drwxr-xr-x 9 root root 4096 Aug 25 19:14 usr", 
            "drwxr-xr-x 13 root root 4096 Feb 25 2015 var"
        ]
    }
}

```

Regarding real-time output for debugging purposes, there is a closed bug report[https://github.com/ansible/ansible/issues/3887#issuecomment-54672569](https://github.com/ansible/ansible/issues/3887#issuecomment-54672569) discussing the reasons why this is not possible and will not be implemented.

Thanks and regards,

Liana melissa,

[Automation developer](https://mindmajix.com/ansible-training).
