There are my .j2 template and playbook to generate hostname, fqdn and ipv4 for all manage node --> vi hosts.j2 {% for i in groups['all'] %}
{{ hostvars[i].inventory_hostname }} {{hostvars[i].ansible_fqdn }} {{hostvars[i].ansible_default_ipv4.address }} {% endfor %} --> vi hosts.yml --- - hosts: all become: yes gather_facts: yes tasks: - name: user template to generate myhosts file template: src: hosts.j2 dest: /home/hostvarsfile When i run the playbook here what i get ansible-playbook hosts.yml PLAY [all] ************************************************************************************************************************************************************** TASK [Gathering Facts] ************************************************************************************************************************************************** ok: [192.168.0.17] fatal: [node12]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host node12 port 22: No route to host", "unreachable": true} ok: [node14] ok: [node16] ok: [node15] TASK [user template to generate myhosts file] *************************************************************************************************************************** fatal: [192.168.0.17]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_fqdn'"} fatal: [node14]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_fqdn'"} fatal: [node16]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_fqdn'"} fatal: [node15]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_fqdn'"} PLAY RECAP ************************************************************************************************************************************************************** 192.168.0.17 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 node12 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0 node14 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 node15 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 node16 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 Can somebody help please -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f5a098ee-d997-4285-af5c-55d22d27e0b1n%40googlegroups.com.