Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug info from custom ansible module

Tags:

python

ansible

I wrote my own ansible module in python. It is working fine, however I would like to report some information during running task (task takes a long time). I know that after execution of task, stdout is written to console.

However, I would like to show some info during execution of task. Is it possible?

like image 734
Docker fun Avatar asked Jan 30 '19 17:01

Docker fun


1 Answers

This is not possible out of the box right now (Ansible 2.7). There's proposal #92 for this.

But there's a way. I've talked about this concept during one of local meetups:

out of band logging

Core idea: wait for log stream inside ansible process on control host (using callback), ssh to remote host with backward tunnel, send logs to "localhost:9999", so they are sent back to control host via tunnel and displayed within ansible process.

Source code available here: https://github.com/berlic/wrikemeetup
Listening callback – callback_plugins/async_debug.py
Sending snippet (send_msg) – module_utils/async_send.py
Demo module – library/slow_mod.py

like image 183
Konstantin Suvorov Avatar answered Sep 28 '22 09:09

Konstantin Suvorov