for ubuntu provision append hostname to 127.0.1.1 line in /etc/hosts

Signed-off-by: Aaron Welch <welch@packet.net>
This commit is contained in:
Aaron Welch
2015-04-21 12:01:40 -04:00
parent 30ae863a4b
commit 2a44f40f6c
2 changed files with 15 additions and 1 deletions

View File

@@ -128,9 +128,17 @@ func (provisioner *UbuntuProvisioner) Hostname() (string, error) {
func (provisioner *UbuntuProvisioner) SetHostname(hostname string) error {
if _, err := provisioner.SSHCommand(fmt.Sprintf(
"sudo hostname %s && echo %q | sudo tee /etc/hostname && echo \"127.0.0.1 %s\" | sudo tee -a /etc/hosts",
"sudo hostname %s && echo %q | sudo tee /etc/hostname",
hostname,
hostname,
)); err != nil {
return err
}
// ubuntu/debian use 127.0.1.1 for non "localhost" loopback hostnames: https://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_hostname_resolution
if _, err := provisioner.SSHCommand(fmt.Sprintf(
"if grep -xq 127.0.1.1.* /etc/hosts; then sudo sed -i 's/^127.0.1.1.*/127.0.1.1 %s/g' /etc/hosts; else echo '127.0.1.1 %s' | sudo tee -a /etc/hosts; fi",
hostname,
hostname,
)); err != nil {
return err