简体   繁体   中英

Ansible playbook to create output to logfile

This is one little part of my working ansible playbook. I want to send the information which will be gathered to a log file (which the playbook will create) I have tried so many different way but getting no where.

No error is coming back which can only tell me that the script is working but I guess its going somewhere else other than the destination which I would like it to do

Here is my script

Would be grateful of your thoughts and help

 - name: netstat check 
   shell: netstat -tulnp | awk '{print $4}' | sed -n 's/.*:\([^",]*\)[",]*$/\1/p'
   register: netstat

 - name: copy output to local file
   copy:
    content: "{{ netstat.stdout}}"
    dest: "/home/user_name/netstat.txt"

Thanks

I executed your playbook in my ansible server(hosts: localhost) and it works fine. A new file is created with the required output.

Incase you want it on the localhost, try giving delegate_to: localhost

- name: copy output to local file
  copy:
    content: "{{ netstat.stdout}}"
    dest: "/home/user_name/netstat.txt"
  delegate_to: localhost  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM