reading a log file with hostname in the playbook processed

17 views
Skip to first unread message

Veera

unread,
Aug 8, 2019, 4:13:48 PM8/8/19
to Ansible Project

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

Karther

unread,
Aug 9, 2019, 3:53:53 AM8/9/19
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages