Class: VagrantPlugins::GuestClearLinux::Cap::ChangeHostName

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-guests-clearlinux/cap/change_host_name.rb

Class Method Summary collapse

Class Method Details

.change_host_name(machine, name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/vagrant-guests-clearlinux/cap/change_host_name.rb', line 8

def self.change_host_name(machine, name)
  machine.communicate.tap do |comm|
    unless comm.test("hostnamectl --static | grep '#{name}'")
      comm.sudo([
        "rm /etc/machine-id",
        "systemd-machine-id-setup",
        "hostnamectl set-hostname --static '#{name}'",
        "hostnamectl set-hostname --transient '#{name}'",
        "hostnamectl set-hostname --set-chassis vm",
        "systemctl restart systemd-networkd.service"
        ].join("\n"))
    end
  end
end