Skip to content

Commit 992c9e3

Browse files
committed
Optionally use ssh settings only with vagrant ssh command
This allows bootstrapping the user on a base image, by using default ssh settings during provisioning and user defined ssh settings when doing `vagrant ssh`.
1 parent d381ab8 commit 992c9e3

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

vagrant/lib/forklift/box_distributor.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,17 @@ def distribute!
6060
end
6161
end
6262

63-
def fetch_from_box_or_settings(box, key)
64-
box.fetch(key) { @settings.fetch(key, nil) }
63+
def fetch_setting(box, key, default = nil)
64+
box.fetch(key) { @settings.fetch(key, default) }
65+
end
66+
67+
def argv_include_any?(tokens)
68+
tokens.any? { |token| ARGV.include?(token) }
69+
end
70+
71+
def add_ssh_setting(box, machine, key)
72+
return if (value = fetch_setting(box, "ssh_#{key}")).nil?
73+
machine.ssh.send("#{key}=", value)
6574
end
6675

6776
def define_vm(config, box = {})
@@ -71,9 +80,9 @@ def define_vm(config, box = {})
7180
machine.vm.box = box.fetch('box_name', nil)
7281
machine.vm.box_version = box.fetch('box_version', nil)
7382

74-
%w[username forward_agent keys_only].each do |key|
75-
unless (value = fetch_from_box_or_settings(box, "ssh_#{key}")).nil?
76-
machine.ssh.send("#{key}=", value)
83+
unless fetch_setting(box, 'use_ssh_settings_vagrant_ssh_only', false) && !argv_include_any?(%w[ssh ssh-config])
84+
%w[username forward_agent keys_only].each do |key|
85+
add_ssh_setting(box, machine, key)
7786
end
7887
end
7988

0 commit comments

Comments
 (0)