Reputation: 151
I execute a shell script in remote hosts using ansible script module. My shell script test.sh is
pwd
echo "hello"
ls -l
My ansible playbook is
- name: Transfer and execute a script.
hosts: server
tasks:
- name: Copy and Execute the script
script: /root/test.sh
Besides, I want to view the execution result of every command in the script. But i only watched result.
changed: [172.18.96.134]
changed: [172.18.96.244]
changed: [172.18.96.245]
How can i watch result like this:
/root
hello
a.txt test.txt
Upvotes: 2
Views: 2115
Reputation: 68074
You can't. It's not possible to trace a module on-line in Ansible. You can write your own log from the script.
Ansible standard way to handle such requirements is Asynchronous Actions and Polling to efficiently handle the output of the potentially large number of hosts.
It's possible to register and print the module's result.
- name: Copy and Execute the script
script: /root/test.sh
register: result
- debug:
var: result.stdout
Upvotes: 3