Ansible: Add IPs from inventory to /etc/hosts of all nodes ...
serverfault.com › questions › 832799Looks like you have errors in your syntax. Also what version of ansible are you using? The variable names may be different. On version 2.2 this works for me: - name: Add IP address of all hosts to all hosts lineinfile: dest: /etc/hosts line: "{{ hostvars[item].ansible_host }} {{ hostvars[item].inventory_hostname }} {{ hostvars[item].inventory_hostname_short }}" state: present with_items ...