Sha256: 5847e1d4b9acf9174e6266dd695b18a847d1bf2839f843a8d92208c9fe217165

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

require 'vagrant/util/guest_hosts'

module VagrantPlugins
  module GuestDarwin
    module Cap
      class ChangeHostName
        extend Vagrant::Util::GuestHosts::BSD

        def self.change_host_name(machine, name)
          comm = machine.communicate

          if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
            basename = name.split(".", 2)[0]

            # LocalHostName should not contain dots - it is used by Bonjour and
            # visible through file sharing services.
            comm.sudo <<-EOH.gsub(/^ */, '')
              # Set hostname
              scutil --set ComputerName '#{name}' &&
                scutil --set HostName '#{name}' &&
                scutil --set LocalHostName '#{basename}'
              result=$?
              if [ $result -ne 0 ]; then
                exit $result
              fi

              hostname '#{name}'
            EOH
          end
          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
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
vagrant-unbundled-2.3.6.0 plugins/guests/darwin/cap/change_host_name.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/guests/darwin/cap/change_host_name.rb
vagrant-unbundled-2.3.3.0 plugins/guests/darwin/cap/change_host_name.rb
vagrant-unbundled-2.3.2.0 plugins/guests/darwin/cap/change_host_name.rb
vagrant-unbundled-2.2.19.0 plugins/guests/darwin/cap/change_host_name.rb
vagrant-unbundled-2.2.18.0 plugins/guests/darwin/cap/change_host_name.rb
vagrant-unbundled-2.2.16.0 plugins/guests/darwin/cap/change_host_name.rb
vagrant-unbundled-2.2.14.0 plugins/guests/darwin/cap/change_host_name.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/guests/darwin/cap/change_host_name.rb
vagrant-unbundled-2.2.10.0 plugins/guests/darwin/cap/change_host_name.rb