Class: VagrantPlugins::GuestSystemd::Cap::ChangeHostName
- Inherits:
-
Object
- Object
- VagrantPlugins::GuestSystemd::Cap::ChangeHostName
- Defined in:
- lib/vagrant-systemd.rb
Class Method Summary collapse
Class Method Details
.change_host_name(machine, name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vagrant-systemd.rb', line 14 def self.change_host_name(machine, name) name = name.split('.') hostname = name.shift domain = name.empty? ? "local" : name.join('.') machine.communicate.tap do |comm| # Only do this if the hostname is not already set if !comm.test("sudo hostname | grep '#{hostname}'") comm.sudo("hostnamectl set-hostname #{hostname}") comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{hostname}.#{domain} #{hostname} @' /etc/hosts") end end end |