# Command within an Ansible variable for Playbook

**URL:** <https://forum.ansible.com/t/command-within-an-ansible-variable-for-playbook/19490>\
**Category:** Ansible Project\
**Created:** [October 12, 2015, 4:46pm UTC](https://forum.ansible.com/t/command-within-an-ansible-variable-for-playbook/19490 "2015-10-12T16:46:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominic\_S\_S](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Dominic\_S\_S](https://forum.ansible.com/u/Dominic_S_S)\
**Post date:** [October 12, 2015, 4:46pm UTC](https://forum.ansible.com/t/command-within-an-ansible-variable-for-playbook/19490/1 "2015-10-12T16:46:17Z")

</div>

Hi,

I am pretty new to ansible, i am trying to get ansible to send me an email from my defined hosts (as in the inventory file

To make the playbook work i have had to hardcode the FROM field within the email module of ansible.

I have hardcoded the playbook file such that the FROM field is the control server .

This works… however the FROM field gives the wrong impression that the email is being sent from the control server , ie root@server1.myserver1 but in other words its coming from each individual server .ie root@server2.myserver… etc

I have 6 servers under ansible control for my lab purposes ie server 1 to server6

---

<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:** [October 24, 2015, 12:02am UTC](https://forum.ansible.com/t/command-within-an-ansible-variable-for-playbook/19490/2 "2015-10-24T00:02:09Z")

</div>

if the hostname envvar is set before you run ansible you can use:

from=root@{{lookup('env', 'HOSTNAME')}}

another option is to just execute `hostname`

from=root@{{lookup('pipe', 'hostname')}}
