Merge pull request #2486 from dongmx/issue2485

issue #2485, In generic driver If a permanent IP address and hostname has alread in /etc/hosts
This commit is contained in:
David Gageot 2015-12-08 09:01:35 +01:00
commit 6583e64e48
1 changed files with 9 additions and 2 deletions

View File

@ -46,8 +46,15 @@ func (provisioner *GenericProvisioner) SetHostname(hostname string) error {
}
// 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",
if _, err := provisioner.SSHCommand(fmt.Sprintf(`
if ! grep -xq .*%s /etc/hosts; then
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
fi`,
hostname,
hostname,
hostname,
)); err != nil {