ansible.builtin.shell not returning output of script

55 views
Skip to first unread message

dimple rohara

unread,
Dec 7, 2021, 6:11:04 PM12/7/21
to Ansible Project
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.

Dick Visser

unread,
Dec 8, 2021, 1:43:16 AM12/8/21
to ansible...@googlegroups.com
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.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/588816c5-646d-46f7-b290-5306f9fdca09n%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

dimple rohara

unread,
Dec 8, 2021, 10:14:31 AM12/8/21
to Ansible Project
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}}.props 2>&1  | tee -a {{log_dir}}/log.out; exit ${PIPESTATUS[0]} "

  register: out

  with_items: [ "{{instances[deployment]}}" ]

- debug: msg= "{{ out }}"


dimple rohara

unread,
Dec 8, 2021, 10:18:35 AM12/8/21
to Ansible Project
the out is showing is "" in debug.

Todd Lewis

unread,
Dec 8, 2021, 10:36:14 AM12/8/21
to ansible...@googlegroups.com, uto...@gmail.com
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
  ansible.builtin.shell: |
    date >> {{ log_dir }}/log.out
    {{sources_dir}}/scripts/tomcat/upgrade.sh {{tmp_dir}}/{{item.name}}.props 2>&1 | \
       tee -a {{log_dir}}/log.out
    exit ${PIPESTATUS[0]}

Nico Kadel-Garcia

unread,
Dec 8, 2021, 11:02:22 AM12/8/21
to ansible...@googlegroups.com, uto...@gmail.com
On Wed, Dec 8, 2021 at 10:36 AM Todd Lewis <uto...@gmail.com> wrote:
>
> 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
> ansible.builtin.shell: |
> date >> {{ log_dir }}/log.out
> {{sources_dir}}/scripts/tomcat/upgrade.sh {{tmp_dir}}/{{item.name}}.props 2>&1 | \
> tee -a {{log_dir}}/log.out
> 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:

set -o pipefail
date 2>&1 | tee -a {{ log_dir }}/log.out
{{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.

> On 12/8/21 10:18 AM, dimple rohara wrote:
>
> the out is showing is "" in debug.
>
> On Wednesday, 8 December 2021 at 10:14:31 UTC-5 dimple rohara wrote:
>>
>> 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}}.props 2>&1 | tee -a {{log_dir}}/log.out; exit ${PIPESTATUS[0]} "
>>
>> register: out
>>
>> with_items: [ "{{instances[deployment]}}" ]
>>
>> - debug: msg= "{{ out }}"
>>
>>
>> On Wednesday, 8 December 2021 at 01:43:16 UTC-5 dick....@geant.org wrote:
>>>
>>> On Wed, 8 Dec 2021 at 00:11, dimple rohara <dimple....@gmail.com> wrote:
>>>>
>>>> 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.
>>>
>>>
>>> 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.
>>>
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1b9e6589-a6cd-d9c4-32d4-87f5a633ed36%40gmail.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages