Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally use ssh settings only with vagrant ssh command #1575

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions vagrant/lib/forklift/box_distributor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,24 @@ def distribute!
end
end

def fetch_from_box_or_settings(box, key)
box.fetch(key) { @settings.fetch(key, nil) }
def fetch_setting(box, key, default = nil)
box.fetch(key) { @settings.fetch(key, default) }
end

def argv_include_any?(tokens)
tokens.any? { |token| ARGV.include?(token) }
end

def add_ssh_setting(box, machine, key)
return if (value = fetch_setting(box, "ssh_#{key}")).nil?
machine.ssh.send("#{key}=", value)
end

def add_ssh_settings(box, machine, keys)
return if fetch_setting(box, 'use_ssh_settings_vagrant_ssh_only', false) && !argv_include_any?(%w[ssh ssh-config])
keys.each do |key|
add_ssh_setting(box, machine, key)
end
end

def define_vm(config, box = {})
Expand All @@ -71,11 +87,7 @@ def define_vm(config, box = {})
machine.vm.box = box.fetch('box_name', nil)
machine.vm.box_version = box.fetch('box_version', nil)

%w[username forward_agent keys_only].each do |key|
unless (value = fetch_from_box_or_settings(box, "ssh_#{key}")).nil?
machine.ssh.send("#{key}=", value)
end
end
add_ssh_settings(box, machine, %w[username forward_agent keys_only])

machine.vm.box_check_update = box.fetch('box_check_update', true)

Expand Down