reading a log file with hostname in the playbook processed

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
    `

Hey,

The variables in ansible write with this synthaxe :

Exemple :

{{ inventory_hostname }}
{{ my_variable }}

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

I hope I helped you

Regards,

Karther