Ansible - Can I print information during module execution?

The answer is simple - no. Ansible is a Continuous system that aims to handle ability to run over a bunch of servers and displaying real-time stdout results can be very unconvenient.

But I think You can use some tricks if Your destination system can support execution in background. I see that Your system is windows, so You have to install cygwin onto it for ability to run background commands like "sleep 20 &" in the example below

You can run this playbook with ansible-playbook -vv background.yml You can see that stdout changing. echo Test---- >> /tmp/test && tail /tmp/test is a demo command. You should output data to some file and tail it for ability to see the progress. Or You may look at file size of stdout file and display it. Use imagination )))

# @file background.yml

- hosts: 127.0.0.1
  connection: local
  gather_facts: no

  tasks:
  - name: Background operation
    shell: "sleep 20 & \ PPID=$! \ echo $PPID"
    register: bcktsk

  - name: Check PPID
    shell: "kill -0 {{ bcktsk.stdout | int + 2 }}"
    register: checkppid
    ignore_errors: true

  - name: Check if process still active
    shell: "echo Test---- >> /tmp/test && tail /tmp/test && kill -0 {{ bcktsk.stdout | int + 2 }}"
    register: test
    when: checkppid.rc == 0
    until: test.rc ==1
    delay: 2
    retries: 10000
    ignore_errors: true

My approach for localhost module:

...
module.log(msg='test!!!!!!!!!!!!!!!!!')
...

Then on another window:

 $ tail -f /var/log/messages

 Nov 29 22:32:44 nfvi-ansible-xxxx python2: ansible-test-module test!!!!!!!!!!!!!!!!!

Tags:

Python

Ansible