Sha256: 853505a237d4c65bce7dde26ad27ccb40972619f8544735c477dccd1a42f0f58

Contents?: true

Size: 999 Bytes

Versions: 3

Compression:

Stored size: 999 Bytes

Contents

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

          if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
            basename = name.split(".", 2)[0]
            comm.sudo <<-EOH.gsub(/^ {14}/, '')
              hostname '#{name}'
              sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network

              sed -i 's/\\(DHCP_HOSTNAME=\\).*/\\1\"#{name}\"/' /etc/sysconfig/interfaces/ifcfg-*

              # Remove comments and blank lines from /etc/hosts
              sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts

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

              # Restart networking
              service network restart
            EOH
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-unbundled-1.9.1.1 plugins/guests/pld/cap/change_host_name.rb
vagrant-unbundled-1.8.5.2 plugins/guests/pld/cap/change_host_name.rb
vagrant-unbundled-1.8.5.1 plugins/guests/pld/cap/change_host_name.rb