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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user