Skip to content

Instantly share code, notes, and snippets.

@jclouds
Created July 30, 2012 00:22
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 jclouds/3202856 to your computer and use it in GitHub Desktop.
Save jclouds/3202856 to your computer and use it in GitHub Desktop.
hostname approach
Here's an approach to ensure at least 2 things are sensible on the host: ${hostname} and ${fqdn}
if ${hostname} is not specified via api, it could be set to the same as the node's name
in private clouds, ${fqdn} may need to come from a property or a conversion fn (ex. = ${hostname}.mydomain.com)
in public clouds, ${fqdn} can be set via api data (ec2.publicDnsName), dns resolution, or x-x-x-x.static.cloud-ips.com
on (centos|fedora|rhel|amzn_linux)-based operating systems
/etc/sysconfig/network: replace line HOSTNAME=${fqdn}
/proc/sys/kernel/hostname: replace w/${fqdn}
on (debian|ubuntu)-based operating systems
/etc/hostname: replace w/${hostname}
exec hostname ${hostname}
on all
/etc/hosts: add or replace line ^127.0.0.1 localhost.localdomain localhost ${hostname}
/etc/hosts: add or replace line ^${public_ip} ${fqdn} ${hostname}
/etc/hosts: add or replace line ^${private_ip} ${hostname}
before attempting to run this script, the input data should be checked to ensure it is valid:
ex. run InternetDomainName.isValid on ${fqdn}
A test could be to logon to the machine and make sure ${fqdn} resolves to ${public_ip} and ${hostname} to ${private_ip}
@jclouds
Copy link
Author

jclouds commented Jul 30, 2012

please help revise this and/or add approaches for other operating systems!

@abayer
Copy link

abayer commented Jul 30, 2012

I'm pretty sure the centos/rhel approach works on SLES too, but I'll verify that tomorrow. Otherwise, yeah, this looks right.

@andreisavu
Copy link

I don't think it's safe to assume ${fqdn} can be resolved to ${public_ip} using external dns infrastructure. A safer approach would be to replicate dns info on all nodes by publishing all (fqdn, ip) pairs in /etc/hosts.

@jclouds
Copy link
Author

jclouds commented Jul 30, 2012

updated gist to clarify that the resolution is a means to test the change, vs a precondition, as you are right: we may not have the same resolver settings as the host does.

That said, I don't think manual dns via updating all machines /etc/hosts files is a sustainable approach, though certainly in tools like Whirr we can do this (as for example we have root access). I'd separate this as 2 steps: 1. correct a machine's configuration (above script) 2. correct DNS server info to be correct (falling back to /etc/hosts update broadcast if for some reason that isn't doable)

wdyt?

@abayer
Copy link

abayer commented Jul 31, 2012

I don't have an aversion to pushing the /etc/hosts fix to tools like Whirr that actually care about it. Seems reasonable.

@andreisavu
Copy link

+1 for implementing this approach

@jclouds
Copy link
Author

jclouds commented Jul 31, 2012

manual dns is a horrible hack, and I will help propagate that hack in tools that desire it, just not as a part of the same script.

@jclouds
Copy link
Author

jclouds commented Jul 31, 2012

remember the sysadmin's decree "do not add hair to the yak! I repeat do not add hair to the yak!"

@jclouds
Copy link
Author

jclouds commented Jul 31, 2012

On the yakkier bit, I'm going to quiz openstack-infra a bit about how they handle this for their jenkins stuff right now. They use puppet, which is pretty fqdn sensitive (ssl certificates and all). Maybe there's an option we can make that doesn't presume tools like whirr know about all machines (ex the puppetmaster) who also need to resolve the new nodes.

On the less yakkier bit, I'll start on it tonight :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment