From 67cde0d9b95460233be9c71aa552ffa3af3c522d Mon Sep 17 00:00:00 2001 From: Justin Filip Date: Mon, 25 May 2015 16:06:51 -0400 Subject: [PATCH] Use hostnamectl to set the hostname on Ubuntu Vivid 15. --- plugins/guests/ubuntu/cap/change_host_name.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/guests/ubuntu/cap/change_host_name.rb b/plugins/guests/ubuntu/cap/change_host_name.rb index beb84d739b7..2519914fcf1 100644 --- a/plugins/guests/ubuntu/cap/change_host_name.rb +++ b/plugins/guests/ubuntu/cap/change_host_name.rb @@ -6,22 +6,39 @@ def self.change_host_name(machine, name) super end + def update_etc_hostname + super unless vivid? + sudo("hostnamectl set-hostname '#{short_hostname}'") + end + def refresh_hostname_service if hardy? # hostname.sh returns 1, so use `true` to get a 0 exitcode sudo("/etc/init.d/hostname.sh start; true") + elsif vivid? + # Service runs via hostnamectl else sudo("service hostname start") end end def hardy? - machine.communicate.test("[ `lsb_release -c -s` = hardy ]") + os_version("hardy") + end + + def vivid? + os_version("vivid") end def renew_dhcp sudo("ifdown -a; ifup -a; ifup -a --allow=hotplug") end + + private + + def os_version(name) + machine.communicate.test("[ `lsb_release -c -s` = #{name} ]") + end end end end