Sha256: a92e5c62c0a60a533470e291c09c93fc60f0a3efde7012a6382e2931a03762bb
Contents?: true
Size: 1.32 KB
Versions: 8
Compression:
Stored size: 1.32 KB
Contents
require 'vagrant/util/guest_hosts' require 'vagrant/util/guest_inspection' module VagrantPlugins module GuestSUSE module Cap class ChangeHostName extend Vagrant::Util::GuestInspection::Linux extend Vagrant::Util::GuestHosts::Linux def self.change_host_name(machine, name) comm = machine.communicate basename = name.split(".", 2)[0] network_with_hostname = machine.config.vm.networks.map {|_, c| c if c[:hostname] }.compact[0] if network_with_hostname replace_host(comm, name, network_with_hostname[:ip]) else add_hostname_to_loopback_interface(comm, name) end if hostnamectl?(comm) if !comm.test("test \"$(hostnamectl --static status)\" = \"#{basename}\"", sudo: false) cmd = <<-EOH.gsub(/^ {14}/, "") hostnamectl set-hostname '#{basename}' echo #{name} > /etc/HOSTNAME EOH comm.sudo(cmd) end else if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) cmd = <<-EOH.gsub(/^ {14}/, "") echo #{name} > /etc/HOSTNAME hostname '#{basename}' EOH comm.sudo(cmd) end end end end end end end
Version data entries
8 entries across 8 versions & 2 rubygems