# hostname variable inside of a file

**URL:** <https://forum.ansible.com/t/hostname-variable-inside-of-a-file/37036>\
**Category:** Ansible Project\
**Created:** [August 25, 2022, 6:04pm UTC](https://forum.ansible.com/t/hostname-variable-inside-of-a-file/37036 "2022-08-25T18:04:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frederick](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@Frederick](https://forum.ansible.com/u/Frederick)\
**Post date:** [August 25, 2022, 6:04pm UTC](https://forum.ansible.com/t/hostname-variable-inside-of-a-file/37036/1 "2022-08-25T18:04:48Z")

</div>

Good Day!

I am very new to Ansible so I apologize. I am trying to make a playbook where I push a file to the client host with the hostname/fqdn inside the file. For example:

My file: cluster/files/etciscsi-initiatorname.iscsi

InitiatorName=iqn.1994-05.com.redhat:{|rhn.system.hostname|}

Where {|rhn.system.hostname|} is replaced with the fqdn that the file is being pushed to. I figured out how to get the ansible\_fqdn from the ansible\_facts but i’m struggling beyond that.

[root@walter tasks]# cat initiatorname.iscsi.yml

---

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [August 25, 2022, 6:10pm UTC](https://forum.ansible.com/t/hostname-variable-inside-of-a-file/37036/2 "2022-08-25T18:10:52Z")

</div>

Are you doing this in a shell loop? Look at the -e option.

Mike

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [August 25, 2022, 6:15pm UTC](https://forum.ansible.com/t/hostname-variable-inside-of-a-file/37036/3 "2022-08-25T18:15:47Z")

</div>

I strongly encourage you to take the Red Hat Ansible class. It is a week long class and worth every penny.

Walter

---

<div class="post-metadata">

**Author:** ![Frederick](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@Frederick](https://forum.ansible.com/u/Frederick)\
**Post date:** [August 25, 2022, 6:30pm UTC](https://forum.ansible.com/t/hostname-variable-inside-of-a-file/37036/4 "2022-08-25T18:30:05Z")

</div>

Thanks!
