2

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

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.