- name: Set the hostname hostname: name: "{{ inventory_hostname_short }}" use: debian - name: Populating hosts file with hostname lineinfile: path: /etc/hosts regexp: '^127.0.1.1' line: '127.0.1.1 {{ ansible_host }} {{ inventory_hostname_short }}'