From 98672819714f25ac4ed59fe6572284d3de8cfd5d Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Thu, 3 Dec 2015 09:34:53 +0100 Subject: [PATCH] provisioners/ansible: allow symbol in `groups` key After c49a146467f7d7a0e441564a2418a1b8a42bb8a6, it makes even more sense to support Symbol datatypes in `groups` option handling. --- plugins/provisioners/ansible/provisioner/base.rb | 4 ++++ test/unit/plugins/provisioners/ansible/provisioner_test.rb | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/provisioners/ansible/provisioner/base.rb b/plugins/provisioners/ansible/provisioner/base.rb index 981cbf5d1..ec8075f99 100644 --- a/plugins/provisioners/ansible/provisioner/base.rb +++ b/plugins/provisioners/ansible/provisioner/base.rb @@ -113,6 +113,10 @@ module VagrantPlugins inventory_groups = "" config.groups.each_pair do |gname, gmembers| + if gname.is_a?(Symbol) + gname = gname.to_s + end + if gmembers.is_a?(String) gmembers = gmembers.split(/\s+/) elsif gmembers.is_a?(Hash) diff --git a/test/unit/plugins/provisioners/ansible/provisioner_test.rb b/test/unit/plugins/provisioners/ansible/provisioner_test.rb index a98f456fb..01b0edbf2 100644 --- a/test/unit/plugins/provisioners/ansible/provisioner_test.rb +++ b/test/unit/plugins/provisioners/ansible/provisioner_test.rb @@ -287,6 +287,7 @@ VF "group1:children" => 'bar', "group2" => [iso_env.machine_names[1]], "group3" => ["unknown", "#{machine.name}"], + group4: [machine.name], "bar" => ["#{machine.name}", "group3"], "bar:children" => ["group1", "group2", "group3", "group4"], } @@ -304,11 +305,13 @@ VF # Skip "unknown" machines expect(inventory_content).to include("[group3]\n#{machine.name}\n") + # Accept Symbol datatype for group names + expect(inventory_content).to include("[group4]\n#{machine.name}\n\n") + # Don't mix group names and host names expect(inventory_content).to include("[bar]\n#{machine.name}\n") # A group of groups only includes declared groups - expect(inventory_content).not_to match(/^group4$/) expect(inventory_content).to include("[bar:children]\ngroup1\ngroup2\ngroup3\n") } end