guests: Always search for FQDN without sudo

This commit is contained in:
Seth Vargo 2016-06-22 19:29:46 -07:00
parent 8f3b6511f2
commit cf91bcf029
No known key found for this signature in database
GPG Key ID: 905A90C2949E8787
15 changed files with 16 additions and 17 deletions

View File

@ -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}'

View File

@ -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}'

View File

@ -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}'")

View File

@ -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}/, '')

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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