# ansible.builtin.shell not returning output of script

**URL:** <https://forum.ansible.com/t/ansible-builtin-shell-not-returning-output-of-script/36079>\
**Category:** Ansible Project\
**Created:** [December 7, 2021, 11:11pm UTC](https://forum.ansible.com/t/ansible-builtin-shell-not-returning-output-of-script/36079 "2021-12-07T23:11:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dimple\_rohara](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dimple\_rohara](https://forum.ansible.com/u/dimple_rohara)\
**Post date:** [December 7, 2021, 11:11pm UTC](https://forum.ansible.com/t/ansible-builtin-shell-not-returning-output-of-script/36079/1 "2021-12-07T23:11:04Z")

</div>

Hi, I am using ansible.builtin.shell, but it’s returning no output of the execution on console.  
I am using it like this:  
ansible.builtin.shell: "{{sources\_dir}}/scripts/tomcat/upgrade.sh {{tmp\_dir}}/{{item.name}}.props 2\>&1 | tee -a {{log\_dir}}/log.out; exit ${PIPESTATUS[0]} "

I am getting the output in the file but nothing on console or the registered variable.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [December 8, 2021, 6:42am UTC](https://forum.ansible.com/t/ansible-builtin-shell-not-returning-output-of-script/36079/2 "2021-12-08T06:42:51Z")

</div>

> Hi, I am using ansible.builtin.shell, but it’s returning no output of the execution on console.  
> I am using it like this:  
> ansible.builtin.shell: "{{sources\_dir}}/scripts/tomcat/upgrade.sh {{tmp\_dir}}/{{[item.name](http://item.name)}}.props 2\>&1 | tee -a {{log\_dir}}/log.out; exit ${PIPESTATUS[0]} "
> 
> I am getting the output in the file but nothing on console or the registered variable.

Which registered variable? The code you’ve posted doesn’t contain any.  
Without that there would indeed be “nothing on console”. So, everything works as it should.

---

<div class="post-metadata">

**Author:** ![dimple\_rohara](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dimple\_rohara](https://forum.ansible.com/u/dimple_rohara)\
**Post date:** [December 8, 2021, 3:14pm UTC](https://forum.ansible.com/t/ansible-builtin-shell-not-returning-output-of-script/36079/3 "2021-12-08T15:14:31Z")

</div>

This is the whole snippet. I have sanitized it a bit so let me know if it doesn’t makes sense.

- name: Test

ansible.builtin.shell: "{{sources\_dir}}/scripts/tomcat/upgrade.sh {{tmp\_dir}}/{{[item.name](http://item.name/)}}.props 2\>&1 | tee -a {{log\_dir}}/log.out; exit ${PIPESTATUS[0]} "

register: out

with\_items: [“{{instances[deployment]}}” ]

- debug: msg= “{{ out }}”

---

<div class="post-metadata">

**Author:** ![dimple\_rohara](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dimple\_rohara](https://forum.ansible.com/u/dimple_rohara)\
**Post date:** [December 8, 2021, 3:18pm UTC](https://forum.ansible.com/t/ansible-builtin-shell-not-returning-output-of-script/36079/4 "2021-12-08T15:18:35Z")

</div>

the out is showing is “” in debug.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [December 8, 2021, 3:35pm UTC](https://forum.ansible.com/t/ansible-builtin-shell-not-returning-output-of-script/36079/5 "2021-12-08T15:35:54Z")

</div>

What’s showing in {{log\_dir}}/log.out? Or rather, what’s _new_ in that file? Since you’re appending to it (tee -a), if it had prior content it would still have that content.  
Maybe throw a date \>\> {{ log\_dir }}/log.out in there before the tomcat upgrade, just to be sure:

```auto
- name: Test
  ansible.builtin.shell: |
    date >> {{ log_dir }}/log.out
    {{sources_dir}}/scripts/tomcat/upgrade.sh {{tmp_dir}}/{{[item.name](http://item.name/)}}.props 2>&1 | \
       tee -a {{log_dir}}/log.out
    exit ${PIPESTATUS[0]}

```

---

<div class="post-metadata">

**Author:** ![Nico\_Kadel-Garcia](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/nico_kadel-garcia/32/9998_2.png) [@Nico\_Kadel-Garcia](https://forum.ansible.com/u/Nico_Kadel-Garcia)\
**Post date:** [December 8, 2021, 4:01pm UTC](https://forum.ansible.com/t/ansible-builtin-shell-not-returning-output-of-script/36079/6 "2021-12-08T16:01:59Z")

</div>

> What's showing in {{log\_dir}}/log.out? Or rather, what's new in that file? Since you're appending to it (tee -a), if it had prior content it would still have that content.  
> Maybe throw a date \>\> {{ log\_dir }}/log.out in there before the tomcat upgrade, just to be sure:
> 
> - name: Test  
> &nbsp;&nbsp;ansible.builtin.shell: |  
> &nbsp;&nbsp;&nbsp;&nbsp;date \>\> {{ log\_dir }}/log.out  
> &nbsp;&nbsp;&nbsp;&nbsp;{{sources\_dir}}/scripts/tomcat/upgrade.sh {{tmp\_dir}}/{{item.name}}.props 2\>&1 | \  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tee -a {{log\_dir}}/log.out  
> &nbsp;&nbsp;&nbsp;&nbsp;exit ${PIPESTATUS[0]}

Shell scripts with "|" in them don't report an exit status of the  
first element automatically, unless "pipefail" is enabled. For  
debugging, I'd suggest using:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set -o pipefail  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;date 2\>&1 | tee -a {{ log\_dir }}/log.out  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{sources\_dir}}/scripts/tomcat/upgrade.sh  
{{tmp\_dir}}/{{item.name}}.props 2\>&1 tee -a {{log\_dir}}/log.out

And if more verbosity is necessary, use "set -x" in your upgrade.sh script.
