diff --git a/plugins/provisioners/ansible/provisioner/base.rb b/plugins/provisioners/ansible/provisioner/base.rb index 51377a61f..981cbf5d1 100644 --- a/plugins/provisioners/ansible/provisioner/base.rb +++ b/plugins/provisioners/ansible/provisioner/base.rb @@ -71,7 +71,12 @@ module VagrantPlugins end def get_inventory_host_vars_string(machine_name) - vars = config.host_vars[machine_name] + # In Ruby, Symbol and String values are different, but + # Vagrant has to unify them for better user experience. + vars = config.host_vars[machine_name.to_sym] + if !vars + vars = config.host_vars[machine_name.to_s] + end s = nil if vars.is_a?(Hash) s = vars.each.collect{ |k, v| "#{k}=#{v}" }.join(" ") diff --git a/test/unit/plugins/provisioners/ansible/provisioner_test.rb b/test/unit/plugins/provisioners/ansible/provisioner_test.rb index cd76d68f8..4a352a29e 100644 --- a/test/unit/plugins/provisioners/ansible/provisioner_test.rb +++ b/test/unit/plugins/provisioners/ansible/provisioner_test.rb @@ -246,6 +246,16 @@ VF expect(inventory_content).to match("^" + Regexp.quote(machine.name) + ".+http_port=80 maxRequestsPerChild=808") } end + + it "retrieves the host variables by machine name, also in String format" do + config.host_vars = { + "machine1" => "http_port=80 maxRequestsPerChild=808" + } + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + inventory_content = File.read(generated_inventory_file) + expect(inventory_content).to match("^" + Regexp.quote(machine.name) + ".+http_port=80 maxRequestsPerChild=808") + } + end end describe "with groups option" do