From cf91bcf029e8c3a95da19631ffc294fec8d6a543 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 22 Jun 2016 19:29:46 -0700 Subject: [PATCH] guests: Always search for FQDN without sudo --- plugins/guests/arch/cap/change_host_name.rb | 2 +- plugins/guests/atomic/cap/change_host_name.rb | 2 +- plugins/guests/coreos/cap/change_host_name.rb | 2 +- plugins/guests/darwin/cap/change_host_name.rb | 2 +- plugins/guests/debian/cap/change_host_name.rb | 2 +- plugins/guests/fedora/cap/change_host_name.rb | 2 +- plugins/guests/freebsd/cap/change_host_name.rb | 5 ++--- plugins/guests/gentoo/cap/change_host_name.rb | 2 +- plugins/guests/omnios/cap/change_host_name.rb | 2 +- plugins/guests/photon/cap/change_host_name.rb | 2 +- plugins/guests/pld/cap/change_host_name.rb | 2 +- plugins/guests/redhat/cap/change_host_name.rb | 2 +- plugins/guests/slackware/cap/change_host_name.rb | 2 +- plugins/guests/suse/cap/change_host_name.rb | 2 +- plugins/guests/ubuntu/cap/change_host_name.rb | 2 +- 15 files changed, 16 insertions(+), 17 deletions(-) diff --git a/plugins/guests/arch/cap/change_host_name.rb b/plugins/guests/arch/cap/change_host_name.rb index f349d444b..d604cf9bf 100644 --- a/plugins/guests/arch/cap/change_host_name.rb +++ b/plugins/guests/arch/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname -f | grep '^#{name}$'") + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, "") hostnamectl set-hostname '#{basename}' diff --git a/plugins/guests/atomic/cap/change_host_name.rb b/plugins/guests/atomic/cap/change_host_name.rb index 9f4b7c44f..74fd081ab 100644 --- a/plugins/guests/atomic/cap/change_host_name.rb +++ b/plugins/guests/atomic/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname -f | grep '^#{name}$'") + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, "") hostnamectl set-hostname '#{basename}' diff --git a/plugins/guests/coreos/cap/change_host_name.rb b/plugins/guests/coreos/cap/change_host_name.rb index f1aeb5bc4..fe9b21865 100644 --- a/plugins/guests/coreos/cap/change_host_name.rb +++ b/plugins/guests/coreos/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname --fqdn | grep -w '#{name}'") + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo("hostname '#{basename}'") diff --git a/plugins/guests/darwin/cap/change_host_name.rb b/plugins/guests/darwin/cap/change_host_name.rb index b7b69faa7..5ef6d9c08 100644 --- a/plugins/guests/darwin/cap/change_host_name.rb +++ b/plugins/guests/darwin/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname -f | grep -w '#{name}' || hostname -s | grep -w '#{name}'") + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, '') diff --git a/plugins/guests/debian/cap/change_host_name.rb b/plugins/guests/debian/cap/change_host_name.rb index fa17ae2b0..b2e972cac 100644 --- a/plugins/guests/debian/cap/change_host_name.rb +++ b/plugins/guests/debian/cap/change_host_name.rb @@ -9,7 +9,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname -f | grep '^#{name}$'") + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, '') # Set the hostname diff --git a/plugins/guests/fedora/cap/change_host_name.rb b/plugins/guests/fedora/cap/change_host_name.rb index f8ceabd11..1add7fd5b 100644 --- a/plugins/guests/fedora/cap/change_host_name.rb +++ b/plugins/guests/fedora/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname | grep -w '#{name}'") + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, "") echo '#{basename}' > /etc/hostname diff --git a/plugins/guests/freebsd/cap/change_host_name.rb b/plugins/guests/freebsd/cap/change_host_name.rb index 09b517e9b..35b924af3 100644 --- a/plugins/guests/freebsd/cap/change_host_name.rb +++ b/plugins/guests/freebsd/cap/change_host_name.rb @@ -3,10 +3,9 @@ module VagrantPlugins module Cap class ChangeHostName def self.change_host_name(machine, name) - options = { shell: "sh" } comm = machine.communicate - if !comm.test("hostname -f | grep '^#{name}$'", options) + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false, shell: "sh") basename = name.split(".", 2)[0] command = <<-EOH.gsub(/^ {14}/, '') # Set the hostname @@ -23,7 +22,7 @@ module VagrantPlugins mv /tmp/tmp-hosts /etc/hosts } EOH - comm.sudo(command, options) + comm.sudo(command, shell: "sh") end end end diff --git a/plugins/guests/gentoo/cap/change_host_name.rb b/plugins/guests/gentoo/cap/change_host_name.rb index c36274e5c..f1f08a55c 100644 --- a/plugins/guests/gentoo/cap/change_host_name.rb +++ b/plugins/guests/gentoo/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname -f | grep '^#{name}$'") + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, "") # Set the hostname diff --git a/plugins/guests/omnios/cap/change_host_name.rb b/plugins/guests/omnios/cap/change_host_name.rb index 4d238d350..9cf9d5b2f 100644 --- a/plugins/guests/omnios/cap/change_host_name.rb +++ b/plugins/guests/omnios/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname | grep -w '#{name}'", sudo: false) + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, '') # Set hostname diff --git a/plugins/guests/photon/cap/change_host_name.rb b/plugins/guests/photon/cap/change_host_name.rb index bb103d24c..49fe25c5b 100644 --- a/plugins/guests/photon/cap/change_host_name.rb +++ b/plugins/guests/photon/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname -f | grep -w '#{name}'", sudo: false) + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, '') # Set the hostname diff --git a/plugins/guests/pld/cap/change_host_name.rb b/plugins/guests/pld/cap/change_host_name.rb index 09dc5eaee..7697c4a20 100644 --- a/plugins/guests/pld/cap/change_host_name.rb +++ b/plugins/guests/pld/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname | grep -w '#{name}'", sudo: false) + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, '') hostname '#{name}' diff --git a/plugins/guests/redhat/cap/change_host_name.rb b/plugins/guests/redhat/cap/change_host_name.rb index 64691b8f5..816ecda21 100644 --- a/plugins/guests/redhat/cap/change_host_name.rb +++ b/plugins/guests/redhat/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname -f | grep -w '#{name}'", sudo: false) + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split('.', 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, '') # Update sysconfig diff --git a/plugins/guests/slackware/cap/change_host_name.rb b/plugins/guests/slackware/cap/change_host_name.rb index d16bfabd0..c8f51e0d6 100644 --- a/plugins/guests/slackware/cap/change_host_name.rb +++ b/plugins/guests/slackware/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname -f | grep -w '#{name}'", sudo: false) + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, '') # Set the hostname diff --git a/plugins/guests/suse/cap/change_host_name.rb b/plugins/guests/suse/cap/change_host_name.rb index a6f291a9c..2e8cc1940 100644 --- a/plugins/guests/suse/cap/change_host_name.rb +++ b/plugins/guests/suse/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname -f | grep -w '#{name}'", sudo: false) + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, '') echo '#{name}' > /etc/HOSTNAME diff --git a/plugins/guests/ubuntu/cap/change_host_name.rb b/plugins/guests/ubuntu/cap/change_host_name.rb index 64dcd4151..ffaec34f4 100644 --- a/plugins/guests/ubuntu/cap/change_host_name.rb +++ b/plugins/guests/ubuntu/cap/change_host_name.rb @@ -5,7 +5,7 @@ module VagrantPlugins def self.change_host_name(machine, name) comm = machine.communicate - if !comm.test("hostname -f | grep -w '#{name}'") + if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, '') # Set the hostname