Sha256: 2302c3d7d7492bbea4fcab25ba76703032ab1c4e72a314b1d97c91ebbe48f6e1

Contents?: true

Size: 908 Bytes

Versions: 6

Compression:

Stored size: 908 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")
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/guests/ubuntu/cap/change_host_name.rb
tnargav-1.2.3 plugins/guests/ubuntu/cap/change_host_name.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/guests/ubuntu/cap/change_host_name.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/plugins/guests/ubuntu/cap/change_host_name.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/plugins/guests/ubuntu/cap/change_host_name.rb
tnargav-1.2.2 plugins/guests/ubuntu/cap/change_host_name.rb