Sha256: 2e2bd949f658c7ed6a5b598f3bdbced0287d08a0bdfa205c0c008b7bea998227

Contents?: true

Size: 979 Bytes

Versions: 2

Compression:

Stored size: 979 Bytes

Contents

module VagrantPlugins
  module GuestUbuntu
    module Cap
      class ChangeHostName
        def self.change_host_name(machine, name)
          machine.communicate.tap do |comm|
            if !comm.test("sudo hostname | grep '^#{name}$'")
              comm.sudo("sed -i 's/.*$/#{name}/' /etc/hostname")
              comm.sudo("sed -i 's@^\\(127[.]0[.]1[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
              if comm.test("[ `lsb_release -c -s` = hardy ]")
                # hostname.sh returns 1, so I grep for the right name in /etc/hostname just to have a 0 exitcode
                comm.sudo("/etc/init.d/hostname.sh start; grep '#{name}' /etc/hostname")
              else
                comm.sudo("service hostname start")
              end
              comm.sudo("hostname --fqdn > /etc/mailname")
              comm.sudo("ifdown -a; ifup -a; ifup -a --allow=hotplug")
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tnargav-1.3.6 plugins/guests/ubuntu/cap/change_host_name.rb
tnargav-1.3.3 plugins/guests/ubuntu/cap/change_host_name.rb