Getting the hostname of the control machine

Hello,

I have a mail task that sends some log files and I would like to make it more clear what process generated them:

  • name: send logs
    mail:
    host: smpthost
    port: 25
    body: “Please review the attached logs from the process. Process executed on {{ ansible_hostname}} triggered by ansible on {{ ansible_control_machine }}”
    attach: log1.txt log2.txt

Of course variable {{ ansible_control_machine }} does not exist. How should I get the name of the control machine. One way I found is to use {{ lookup(‘env’,‘HOSTNAME’) }}. Is there another way without relying on environment variables? What if I want to access a random fact of the control machine?

Thank you very much for your response!

Regards
Rambius

several ways, here are 2:

local_action: shell hostname
register: hostname

or

lookup('pipe', 'hostname')

Hello,

вторник, 27 юни 2017 г., 16:23:22 UTC-4, Brian Coca написа:

several ways, here are 2:

local_action: shell hostname
register: hostname

or

lookup(‘pipe’, ‘hostname’)

Both ways work. Thank you for your help.

Regards
Rambius