Sha256: d6b1ab36ac51fd6583f8bc2bf5042e8411030adb4baaef4fdd1277dd776d0208

Contents?: true

Size: 637 Bytes

Versions: 3

Compression:

Stored size: 637 Bytes

Contents

module VagrantPlugins
  module GuestSUSE
    module Cap
      class ChangeHostName
        def self.change_host_name(machine, name)
          comm = machine.communicate

          if !comm.test("getent hosts '#{name}'", sudo: false)
            basename = name.split(".", 2)[0]
            comm.sudo <<-EOH.gsub(/^ {14}/, '')
              hostnamectl set-hostname '#{basename}'

              # Prepend ourselves to /etc/hosts
              grep -w '#{name}' /etc/hosts || {
                sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
              }
            EOH
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-unbundled-2.2.6.2 plugins/guests/suse/cap/change_host_name.rb
vagrant-unbundled-2.2.6.1 plugins/guests/suse/cap/change_host_name.rb
vagrant-unbundled-2.2.6.0 plugins/guests/suse/cap/change_host_name.rb