0

If I'm not mistaken, we can print out debug (stdout/stderr) logs of bash after task is done in Ansible.

hello-world.sh

ping -c 5 www.google.com

my-playbook.yml

tasks:
  - block:
      - name: Print out hello world
        command: "./hello-world.sh"
        register: result
      - debug: var=result.stdout_lines
  - name: Print script execution result
    ansible.builtin.debug:
      var: result
      verbosity: 4

Regarding above, ping results will be printed out after 5 times reach. That's why I'm curious to know how to print out each ping result while task is running in Ansible instead of task completed.

PPShein
  • 13,309
  • 42
  • 142
  • 227
  • 1
    Sadly, as far as I know there is no way to do what you want in ansible, since it is a "run this script and tell me what happened" and not "be a copy of expect driving an ssh connection" – mdaniel Apr 09 '22 at 17:32

1 Answers1

2

According Introduction to modules and Return Values

Ansible executes each module, usually on the remote managed node, and collects return values.

and

Ansible modules normally return a data structure that can be registered into a variable ...

such live output is not implemented.

Regarding your question

How to print out each ping result while task is running in Ansible instead?

there is an option for Debugging modules

To see what is actually happening in the module

but that is probably not you were looking for in your use case.


An other option might be

U880D
  • 8,601
  • 6
  • 24
  • 40