Reputation: 27
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
Upvotes: 2
Views: 1747
Reputation: 2568
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
Upvotes: 1