Sha256: 75b4800f45cb5aeb0ec687d341d1615e7eed78f30a29e4f6cd716306d84532af

Contents?: true

Size: 880 Bytes

Versions: 3

Compression:

Stored size: 880 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.execute("bash /tmp/vagrant-change-hostname")
              comm.execute("rm -f /tmp/vagrant-change-hostname")
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-vyatta-0.0.5 lib/vagrant-vyatta/cap/change_host_name.rb
vagrant-vyatta-0.0.4 lib/vagrant-vyatta/cap/change_host_name.rb
vagrant-vyatta-0.0.3 lib/vagrant-vyatta/cap/change_host_name.rb