Sha256: ccd4cb88fcb255ae943d2a63edec4c8d900ef54c2f42e72518a0fcb62e42531f

Contents?: true

Size: 799 Bytes

Versions: 7

Compression:

Stored size: 799 Bytes

Contents

module VagrantPlugins
  module GuestPld
    module Cap
      class ChangeHostName
        def self.change_host_name(machine, name)
          machine.communicate.tap do |comm|
            # Only do this if the hostname is not already set
            if !comm.test("sudo hostname | grep --line-regexp '#{name}'")
              comm.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network")
              comm.sudo("hostname #{name}")
              comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
              comm.sudo("sed -i 's/\\(DHCP_HOSTNAME=\\).*/\\1\"#{name}\"/' /etc/sysconfig/interfaces/ifcfg-*")
              comm.sudo("service network restart")
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 4 versions & 3 rubygems

Version Path
vagrant-unbundled-1.8.1.2 plugins/guests/pld/cap/change_host_name.rb
vagrant-unbundled-1.8.1.1 plugins/guests/pld/cap/change_host_name.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-272fb27e0536/plugins/guests/pld/cap/change_host_name.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-b421af58e8b3/plugins/guests/pld/cap/change_host_name.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-309e896975d1/plugins/guests/pld/cap/change_host_name.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-1cf2a8db4ccb/plugins/guests/pld/cap/change_host_name.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/bundler/gems/vagrant-1e28f1ac31e7/plugins/guests/pld/cap/change_host_name.rb