Skip to content

Instantly share code, notes, and snippets.

@TJM
Created May 1, 2015 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TJM/6fb2191f321ce92b4183 to your computer and use it in GitHub Desktop.
Save TJM/6fb2191f321ce92b4183 to your computer and use it in GitHub Desktop.
Foreman fix_hosts
<%#
kind: snippet
name: fix_hosts
%>
echo "<%= @host %>" > /etc/hostname
hostname <%= @host %>
# CentOS 7 (Fedora 19+?) uses hostnamectl
[ -x /usr/bin/hostnamectl ] && /usr/bin/hostnamectl set-hostname <%= @host %>
# Cloud Init Data needs to be told to leave the hostname alone.
[ -f /etc/cloud/cloud.cfg ] && echo 'preserve_hostname: true' >> /etc/cloud/cloud.cfg
cat > /etc/hosts << EOF
<%# simple snippet to generate /etc/hosts when provisioning image based systems -%>
127.0.0.1 <%= @host %> <%= @host.shortname %> localhost localhost.localdomain
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment