How to print on screen in Ansible

If you can’t but really want

George Shuklin
OpsOps
1 min readOct 23, 2019

--

Sometime you want to print something on the screen in the middle of playbook. You have measly debug module, and, that’s all.

How about multi-line text with colors, formatting, etc, etc?

Officially you can’t do this. But if you are REAALLY motivated… Nothing can stop you.

The solution

Use /dev/tty

Example

And, of course, you can jinja as you want to write a lengthy messages, you can print files (cat), show output for other utilities (echo reg.stdout > /dev/tty), etc.

One important note: we are talking about localhost /dev/tty, don’t try this on remote servers.

If example with escape codes is too scary, here the simpler example:

Have fun!

--

--

George Shuklin
OpsOps

I work at Servers.com, most of my stories are about Ansible, Ceph, Python, Openstack and Linux. My hobby is Rust.