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

Version Path
vagrant-unbundled-2.3.6.0 plugins/guests/suse/cap/change_host_name.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/guests/suse/cap/change_host_name.rb
vagrant-unbundled-2.3.3.0 plugins/guests/suse/cap/change_host_name.rb
vagrant-unbundled-2.3.2.0 plugins/guests/suse/cap/change_host_name.rb
vagrant-unbundled-2.2.19.0 plugins/guests/suse/cap/change_host_name.rb
vagrant-unbundled-2.2.18.0 plugins/guests/suse/cap/change_host_name.rb
vagrant-unbundled-2.2.16.0 plugins/guests/suse/cap/change_host_name.rb
vagrant-unbundled-2.2.14.0 plugins/guests/suse/cap/change_host_name.rb