Something like this will do the trick: - name: Content hosts: elkmaster gather_facts: no vars: report_file: "/home/jrua/report.txt" tasks: - name: create file file: dest: "{{ report_file }}" state: touch delegate_to: localhost
- name: copy content lineinfile: line: "{{ hostvars[inventory_hostname]['inventory_hostname_short'] + ':' + hostvars[inventory_hostname]['ip'] }}" dest: "{{ report_file }}" insertafter: EOF delegate_to: localhost loop: "{{ groups['elkmaster'] }}" Using as inventory : [elkmaster] es_master ip='1.1.1.1' es_data01 ip='2.3.3.4' [elkdata] es_data01 ip='2.3.3.4' es_data02 ip='21.21.21.1' Results in: es_master:1.1.1.1 es_data01:2.3.3.4 HTH, Regards El jue., 12 nov. 2020 a las 13:23, gr00t (<numimick...@gmail.com>) escribió: > HI, > > <https://stackoverflow.com/posts/64803839/timeline> > > I am trying to create a task that will get the host target IP address and > host-name that are in the inventory then save it to a file in the local > directory. > > Would love to save the data like this: > *hostname:ip-address * > > Kindly assist, don't know where to start? > > /gr00t > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Development" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to ansible-devel+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-devel/5d83bbf6-23d7-4c31-a7f6-52631e14816cn%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-devel/5d83bbf6-23d7-4c31-a7f6-52631e14816cn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Ansible Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/CAFtje5PAqMDtf6q7BdPgvQg6qrX1D7%2BvE3%2BH7OWQ2%2Bp3u_%2BMVA%40mail.gmail.com.