From 2416149aa36ea58accf0833f0e5ca3c6b95c59eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 27 Nov 2013 09:35:18 +0200 Subject: [PATCH] fix hostname change on pld --- plugins/guests/pld/cap/change_host_name.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 plugins/guests/pld/cap/change_host_name.rb diff --git a/plugins/guests/pld/cap/change_host_name.rb b/plugins/guests/pld/cap/change_host_name.rb new file mode 100644 index 000000000..e7925b03b --- /dev/null +++ b/plugins/guests/pld/cap/change_host_name.rb @@ -0,0 +1,20 @@ +module VagrantPlugins + module GuestPld + module Cap + class ChangeHostName + def self.change_host_name(machine, name) + machine.communicate.tap do |comm| + # Only do this if the hostname is not already set + if !comm.test("sudo hostname | grep --line-regexp '#{name}'") + comm.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network") + comm.sudo("hostname #{name}") + comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts") + comm.sudo("sed -i 's/\\(DHCP_HOSTNAME=\\).*/\\1\"#{name}\"/' /etc/sysconfig/interfaces/ifcfg-*") + comm.sudo("service network restart") + end + end + end + end + end + end +end