{"action":"opened","issue":{"url":"https://api.github.com/repos/holms/ansible-fqdn/issues/3","labels_url":"https://api.github.com/repos/holms/ansible-fqdn/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/holms/ansible-fqdn/issues/3/comments","events_url":"https://api.github.com/repos/holms/ansible-fqdn/issues/3/events","html_url":"https://github.com/holms/ansible-fqdn/issues/3","id":89815948,"number":3,"title":"printing correct entries in /etc/hosts","user":{"login":"ksingh7","id":9701902,"avatar_url":"https://avatars.githubusercontent.com/u/9701902?v=3","gravatar_id":"","url":"https://api.github.com/users/ksingh7","html_url":"https://github.com/ksingh7","followers_url":"https://api.github.com/users/ksingh7/followers","following_url":"https://api.github.com/users/ksingh7/following{/other_user}","gists_url":"https://api.github.com/users/ksingh7/gists{/gist_id}","starred_url":"https://api.github.com/users/ksingh7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ksingh7/subscriptions","organizations_url":"https://api.github.com/users/ksingh7/orgs","repos_url":"https://api.github.com/users/ksingh7/repos","events_url":"https://api.github.com/users/ksingh7/events{/privacy}","received_events_url":"https://api.github.com/users/ksingh7/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-20T20:43:09Z","updated_at":"2015-06-20T20:43:09Z","closed_at":null,"body":"Hi , to get correct value in /etc/hosts you should use ``` {{ hostvars[item].ansible_hostname }}.{{ fqdn }} ```\r\n\r\nit will print in /etc/hosts as\r\n\r\n``` 10.188.0.47 one.csc.fi one ```  ( IP FQDN HOSTNAME )\r\n\r\nuse below in default.yml\r\n\r\n```\r\n  lineinfile: dest=/etc/hosts regexp='{{ hostvars[item].ansible_hostname }}$' line='{{ hostvars[item].ansible_default_ipv4.address }} {{ hostvars[item].ansible_hostname }}.{{ fqdn }} {{ item }}' state=present backup=yes\r\n```"}}