Hi
I am trying to achieve all running processes on our linux machines via ansible and get output in a file along with each host name and processes. I have made below playbook but not getting to the point how to get list of processes for each host one by one and store in a file. Can anyone please help with the code how can I achieve this? I am using with_items with list of hosts which is coming from inventory group hostlist. many thanks
I just changed the host as devops
HI Bishwajit Samanta
Thanks. It is creating file for each hostname but data is not in readable format. Are you able to do favor little more, how to get the data in each file as orignal form like as processes list show on linux machine? I was initially thinking to get output from all hosts in one file and somehow get processes list along with hostname one by one. But this can work as well. Many Thanks.
Thanks. It is creating file for each hostname but data is not in readable
format. Are you able to do favor little more, how to get the data in each
file as orignal form like as processes list show on linux machine?
Replace {{ output }} with {{ output.stdout }}
I was
initially thinking to get output from all hosts in one file and somehow get
processes list along with hostname one by one. But this can work as well.
To do that you need to use jinja template, something like this should work.
- name: Getting some details of systems
copy:
content: |
{% for i in ansible_play_hosts %}
Output for host {{ i }}:
{{ hostvars[i].output.stdout }}
{% endfor %}
dest: /my/file
delegate: localhost