# reading a log file  with  hostname in the playbook processed

**URL:** <https://forum.ansible.com/t/reading-a-log-file-with-hostname-in-the-playbook-processed/30995>\
**Category:** Ansible Project\
**Created:** [August 8, 2019, 8:13pm UTC](https://forum.ansible.com/t/reading-a-log-file-with-hostname-in-the-playbook-processed/30995 "2019-08-08T20:13:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [August 8, 2019, 8:13pm UTC](https://forum.ansible.com/t/reading-a-log-file-with-hostname-in-the-playbook-processed/30995/1 "2019-08-08T20:13:47Z")

</div>

I am trying to create a log file with hostname with it by using the shell variable and not from {{ ansible\_hostname }} , as I have my playbooks have gather\_facts disabled.

Unable to fetch the source file as ansible is unable to get the exact file in src.?

what need to be changed for the line "src: /var/tmp/patchreport\_$(hostname -s)\_$(date +%F) "

`

- name: myplay  
hosts: myhost5  
remote\_user: root  
gather\_facts: no  
tasks:

- name: Collecting the patch result  
ignore\_errors: yes  
shell: grep “`date '+%b.%d'`” /var/log/yum.log \> /var/tmp/patchreport\_$(hostname -s)\_$(date +%F)  
register: patchlog

- name: Fetch the Patch result for the server  
fetch:  
src: /var/tmp/patchreport\_$(hostname -s)\_$(date +%F)  
dest: /home/devops/patch\_reports  
when: patchlog.changed  
`

---

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [August 9, 2019, 7:53am UTC](https://forum.ansible.com/t/reading-a-log-file-with-hostname-in-the-playbook-processed/30995/2 "2019-08-09T07:53:52Z")

</div>

Hey,

The variables in ansible write with this synthaxe :

Exemple :

{{ inventory\_hostname }}  
{{ my\_variable }}

If you write (hostname -s), ansible not understand this synthaxe 😕

I hope I helped you

Regards,

Karther
