I need help extracting hosts informations from /etc/hosts file and exporting that content to a predefined file. I created a Ansible's Playbook to this task, but the content is not written on the output file. Do you guys, can help me, please?
Following Playbook:
- hosts: sigt-temp
become: yes
become_user: root
gather_facts: yes
tasks:
- name: Collecting Data
shell:
cmd: grep -P -i '^10\.129\.' /etc/hosts
register: etc_hosts
- name: Collecting Data
debug: var=ansible_hostname,ansible_default_ipv4['address'],etc_hosts
- name: Output info
local_action: lineinfile path=./etc-hosts.txt line={{ansible_hostname}};{{ansible_default_ipv4['address']}};{{etc_hosts}}; create=yes
- name: Validation
debug: var=etc_hosts.stdout_lines