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.
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.
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](http://item.name/)}}.props 2>&1 | \
tee -a {{log_dir}}/log.out
exit ${PIPESTATUS[0]}
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.