How to log something in a custom module ?

Hi,

I would like to know how to log some variable or other useful information directly in the “Ansible log” displayed when using “-vvvv”.

I tried Display(), but it seems to be not in the same “context”.

So what do you advice for log information into a custom module ?

Thanks :slight_smile:

You have to be a more specific, modules have several ways of returning
information back to the controller vs 'logging' information (
`AnsibleModule.log()` method should handle that to the local remote
system). If you want to return information back to the controller you
can just make it part of the results the module returns, you can also
use module methods to issue warnings or deprecations.

What I would like to do it’s like this debut output :

TASK [Get system] ******************************************************************************************************************************************************************************
task path: /home/user/playbooks/pb_banner.yml:24
<1.1.1.1> attempting to start connection
<1.1.1.1> using connection plugin network_cli
<1.1.1.1> local domain socket does not exist, starting it
<1.1.1.1> control socket path is /home/user/.ansible/pc/d7df86492e
<1.1.1.1> CUSTOM NETWORK_CLI MODULE
<1.1.1.1> <1.1.1.1> ESTABLISH PARAMIKO SSH CONNECTION FOR USER: user on PORT 22 TO 1.1.1.1
<1.1.1.1> <1.1.1.1> ssh connection done, setting terminal
<1.1.1.1> <1.1.1.1> loaded terminal plugin for network_os fortios
<1.1.1.1> <1.1.1.1> loaded cliconf plugin for network_os fortios
<1.1.1.1> <1.1.1.1> Response received, triggered ‘persistent_buffer_read_timeout’ timer of 0.1 seconds
<1.1.1.1> <1.1.1.1> firing event: on_open_shell()

<1.1.1.1> prompt detected on device DEVICENAME # <<<<====

The last line is printed during the call of “on_open_shell” in the “terminal_plugins” (bellow, the source code), as you can see, I use “Display()”.

def on_open_shell(self):
    prompt = self._get_prompt()

    if re.search("Press 'a' to accept", prompt):
        self._exec_cli_command(b'a')
    if prompt:
        display.display('prompt detected on device ' + prompt)

And now I would like to have the same kind of log in the “debug mode (-vvvv)”, but from a cliconf_plugin.

I dont want to like into a file.

I hope i’m clear :slight_smile: thanks for your help !