- name: Set hostname # Use double quoted scalars to force expansion of escape sequences # cf. https://groups.google.com/forum/#!topic/ansible-project/ZaB6o-eqDzw copy: "content='{{ inventory_hostname_short }}\n' dest=/etc/hostname owner=root group=root mode=0644" tags: hostname notify: - Refresh hostname - name: Set mailname copy: "content='{{ inventory_hostname }}\n' dest=/etc/mailname owner=root group=root mode=0644" tags: mailname - name: Fix /etc/hosts (1) lineinfile: "dest=/etc/hosts create=yes regexp='^127\\.0\\.0\\.1\\s+' line='127.0.0.1\tlocalhost'" tags: hosts - name: Fix /etc/hosts (2) lineinfile: "dest=/etc/hosts create=yes regexp='^127\\.0\\.1\\.1\\s+' line='127.0.1.1\t{{ inventory_hostname }} {{ inventory_hostname_short }}'" tags: hosts - meta: flush_handlers