Skip to content

Instantly share code, notes, and snippets.

@alfredodeza
Created April 28, 2016 12:07
Show Gist options
  • Save alfredodeza/5104d34ea88f910482116a531578c290 to your computer and use it in GitHub Desktop.
Save alfredodeza/5104d34ea88f910482116a531578c290 to your computer and use it in GitHub Desktop.
ensure that the current `hostname` is defined in `/etc/hosts`
---
# Because not everything is correct in this world, we may end up with a host that doesn't have the reported
# hostname in the hosts file.
- name: ensure that the current host is in /etc/hosts. Yes this is a thing.
sudo: true
replace:
backup: yes
dest: /etc/hosts
regexp: '^(127\.0\.1\.1(?!.*\b{{ ansible_hostname }}\b).*)$'
replace: '\1 {{ ansible_hostname }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment