# Debug Script task

**URL:** <https://forum.ansible.com/t/debug-script-task/19482>\
**Category:** Ansible Project\
**Created:** [October 11, 2015, 11:24am UTC](https://forum.ansible.com/t/debug-script-task/19482 "2015-10-11T11:24:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doron\_Shai](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Doron\_Shai](https://forum.ansible.com/u/Doron_Shai)\
**Post date:** [October 11, 2015, 11:24am UTC](https://forum.ansible.com/t/debug-script-task/19482/1 "2015-10-11T11:24:56Z")

</div>

Hi All,

I am new to ansible, and i have a script which i use on many hosts.

The command i execute is

> > > **_ansible-playbook main.yml -i hosts_**

here is my code in the main.yml

> > > **_—_**
> 
> > > **_- hosts: group_**
> 
> > > **_sudo: true_**
> 
> > > **_user: root_**
> 
> > >
> 
> > > **_tasks:_**
> 
> > > **_- name: Clean logs_**
> 
> > > **_script: Clean.sh_**
> 
> > > **_register: myEcho_**
> 
> > >
> 
> > > **_- name: Debug_**
> 
> > > **_debug: msg=“{{ myEcho.stdout\_lines }}”_**

Here is the script that i execute using the Ansible task:

> > > **_echo ‘====================== cb-backend-00 ======================’_**
> 
> > > **_echo ‘======================== CleanLogsOld =========================’_**
> 
> > > **_du -h /opt/test/logs/logs.old/ --max-depth=0_**
> 
> > > **_if ls /opt/test/logs/logs.old/\* 1\> /dev/null 2\>&1; then_**
> 
> > > **_echo “There are files under the Old Logs Folder”_**
> 
> > > **_rm -rf /opt/test/logs/logs.old/\*_**
> 
> > > **_else_**
> 
> > > **_echo “====== No Files exist under the Old Logs folder”_**
> 
> > > **_fi_**
> 
> > > **_exit_**

Here is the output that i get:

> > > **_PLAY [group] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_**
> 
> > >
> 
> > > **_GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_**
> 
> > > **_ok: [20.152.30.10]_**
> 
> > >
> 
> > > **_TASK: [Clean BVT] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_**
> 
> > > **_changed: [20.152.30.10]_**
> 
> > >
> 
> > > **_TASK: [Debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_**
> 
> > > **_ok: [20.152.30.10] =\> {_**
> 
> > > **_“msg”: “[]”_**
> 
> > > **_}_**
> 
> > >
> 
> > > **_PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_**
> 
> > > **_20.152.30.10 : ok=3 changed=1 unreachable=0 failed=0_**

What do i miss? Why I can not see all the echo commands that I wrote?

Thanks,  
Doron

---

<div class="post-metadata">

**Author:** ![Markus\_Ellers](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Markus\_Ellers](https://forum.ansible.com/u/Markus_Ellers)\
**Post date:** [October 12, 2015, 5:12pm UTC](https://forum.ansible.com/t/debug-script-task/19482/2 "2015-10-12T17:12:18Z")

</div>

I’m not a big expert on Syntax, but try changing the debug Task to this:

- name: Debug  
debug: var=myEcho.stdout

I have a similar thing in one of my playbooks and it works. I hope this helps.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 12, 2015, 5:52pm UTC](https://forum.ansible.com/t/debug-script-task/19482/3 "2015-10-12T17:52:35Z")

</div>

"msg": "" indicates that stdout is empty, use

debug: var=myEcho

You should get the output of stderr and rc, which might have a clue to  
what is wrong.  
You can also run with -vvvv to get more info on the execution.
