Sha256: cdb5c80e3e914bca4d8405e4e0a8f23ac651191af43e090f75998eb342c9625f

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

require "log4r"

module Vagrant
  module Action
    module Builtin
      # This middleware sets the hostname of the guest according to the
      # "vm.hostname" configuration parameter if it is set. This middleware
      # should be placed such that the after the @app.call, a booted machine
      # is available (this generally means BEFORE the boot middleware).
      class SetHostname
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new("vagrant::action::builtin::set_hostname")
        end

        def call(env)
          @app.call(env)

          hostname = env[:machine].config.vm.hostname
          allow_hosts_modification = env[:machine].config.vm.allow_hosts_modification
          if !hostname.nil? && allow_hosts_modification
            env[:ui].info I18n.t("vagrant.actions.vm.hostname.setting")
            env[:machine].guest.capability(:change_host_name, hostname)
          else
            @logger.info("`allow_hosts_modification` set to false. Hosts modification has been disabled, skiping changing hostname.")
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
vagrant-unbundled-2.3.6.0 lib/vagrant/action/builtin/set_hostname.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/lib/vagrant/action/builtin/set_hostname.rb
vagrant-unbundled-2.3.3.0 lib/vagrant/action/builtin/set_hostname.rb
vagrant-unbundled-2.3.2.0 lib/vagrant/action/builtin/set_hostname.rb
vagrant-unbundled-2.2.19.0 lib/vagrant/action/builtin/set_hostname.rb
vagrant-unbundled-2.2.18.0 lib/vagrant/action/builtin/set_hostname.rb
vagrant-unbundled-2.2.16.0 lib/vagrant/action/builtin/set_hostname.rb
vagrant-unbundled-2.2.14.0 lib/vagrant/action/builtin/set_hostname.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/lib/vagrant/action/builtin/set_hostname.rb
vagrant-unbundled-2.2.10.0 lib/vagrant/action/builtin/set_hostname.rb