Sha256: 5fe779dd24bd948073d543c0d99df8832c7d47b0c7071fded43a36f480bb9a16

Contents?: true

Size: 881 Bytes

Versions: 2

Compression:

Stored size: 881 Bytes

Contents

require 'tempfile'

module VagrantPlugins
  module GuestVyatta
    module Cap
      class ChangeHostName
        def self.change_host_name(machine, name)
          machine.communicate.tap do |comm|
            if !comm.test("sudo hostname | grep '^#{name}$'")

              commands = <<-EOS
WRAPPER=/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper
. /etc/bash_completion
$WRAPPER begin
$WRAPPER set system host-name #{name}
$WRAPPER commit
$WRAPPER save
$WRAPPER end
              EOS

              temp = Tempfile.new("vagrant")
              temp.binmode
              temp.write(commands)
              temp.close

              comm.upload(temp.path, "/tmp/vagrant-change-hostname")
              comm.sudo("sudo bash /tmp/vagrant-change-hostname")
              comm.sudo("sudo rm /tmp/vagrant-change-hostname")
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vagrant-vyatta-0.0.2 lib/vagrant-vyatta/cap/change_host_name.rb
vagrant-vyatta-0.0.1 lib/vagrant-vyatta/cap/change_host_name.rb