# Custom module: Using Display() to print messages (ideally in real time) over a local connection

**URL:** <https://forum.ansible.com/t/custom-module-using-display-to-print-messages-ideally-in-real-time-over-a-local-connection/20957>\
**Category:** Ansible Developer\
**Tags:** ubuntu\
**Created:** [March 22, 2016, 5:12pm UTC](https://forum.ansible.com/t/custom-module-using-display-to-print-messages-ideally-in-real-time-over-a-local-connection/20957 "2016-03-22T17:12:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florin\_Lipan](https://avatars.discourse-cdn.com/v4/letter/f/7ba0ec/32.png) [@Florin\_Lipan](https://forum.ansible.com/u/Florin_Lipan)\
**Post date:** [March 22, 2016, 5:12pm UTC](https://forum.ansible.com/t/custom-module-using-display-to-print-messages-ideally-in-real-time-over-a-local-connection/20957/1 "2016-03-22T17:12:04Z")

</div>

I’m running a set of custom Ansible modules which are ment for local connections only.

I was trying to use [Display()](https://github.com/ansible/ansible/blob/00b8b4911203724f5fdc6631240a62c0ac924a6f/lib/ansible/utils/display.py) to print out some custom output - ideally in real time. I’m using Ansible 2.0.1.0 on Ubuntu 14.04.

This would be my (simplified) custom module:

`

```auto
# library/output.py

#!/usr/bin/python

from ansible.utils.display import Display
display = Display() # also tried Display(x) here - where x = 0..5
display.display(u"hello world")
display.vv(u"hello world")
display.banner(u"hello world")

print "{}"

```

`

This would be the playbook using the custom module (emphasis on the local connection):

`

```auto
# output.yml

- hosts: localhost
  connection: local
  tasks:
  - output:

```

`

And these are the various ways I tried to run this:

`

```auto
ansible-playbook output.yml
ansible-playbook output.yml -vvv
ansible-playbook output.yml -f 1
PYTHONUNBUFFERED=1 ansible-playbook output.yml

```

`

I also tried combinations of these (one fork & verbose etc.)

I was expecting at least one the “hello world” messages to show up in the output, however none of the commands did print anything:

`

```auto
PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [output] ******************************************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 

```

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 22, 2016, 6:46pm UTC](https://forum.ansible.com/t/custom-module-using-display-to-print-messages-ideally-in-real-time-over-a-local-connection/20957/2 "2016-03-22T18:46:21Z")

</div>

That won’t work, modules are run in their own fork and their stdout/stderr are captured into the task results.

So using Display or direct print will not send the output directly to the user’s screen. Currently modules have no way of doing this, I am working on adding an update\_json function that cand do this but it is still not ready.

---

<div class="post-metadata">

**Author:** ![Florin\_Lipan](https://avatars.discourse-cdn.com/v4/letter/f/7ba0ec/32.png) [@Florin\_Lipan](https://forum.ansible.com/u/Florin_Lipan)\
**Post date:** [March 23, 2016, 8:33am UTC](https://forum.ansible.com/t/custom-module-using-display-to-print-messages-ideally-in-real-time-over-a-local-connection/20957/3 "2016-03-23T08:33:34Z")

</div>

Thanks Brian! I’m looking forward to update\_json

---

<div class="post-metadata">

**Author:** ![Thomas\_Decaux](https://avatars.discourse-cdn.com/v4/letter/t/ba8739/32.png) [@Thomas\_Decaux](https://forum.ansible.com/u/Thomas_Decaux)\
**Post date:** [November 9, 2020, 9:04am UTC](https://forum.ansible.com/t/custom-module-using-display-to-print-messages-ideally-in-real-time-over-a-local-connection/20957/4 "2020-11-09T09:04:26Z")

</div>

You can use “action” for that.
