From b741ff799940064f12315f3f57b2298acfdb8318 Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Sun, 3 Sep 2017 17:09:16 +0200 Subject: [PATCH] provisoners/ansible(both): Accept 'all:vars' The patterns "all" is a special keyword that target all hosts in the inventory. Therefore it makes sense to accept "all:vars" as a group variable name. Note that "*:vars" pattern is not valid in an Ansible inventory. See http://docs.ansible.com/ansible/latest/intro_patterns.html#patterns Fix #7730 --- CHANGELOG.md | 1 + plugins/provisioners/ansible/provisioner/base.rb | 2 +- .../provisioners/ansible/provisioner_test.rb | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8fdf7e29..1d40c57f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ IMPROVEMENTS: BUG FIXES: - guests/shell_expand_guest_path : Properly expand guest paths that include relative path alias [GH-8918] +- provisioners/ansible(both): Add the "all:vars" section to the inventory when defined in `groups` option [GH-7730] - util/ssh: Properly quote key path for IdentityFile option to allow for spaces [GH-8924] ## 1.9.8 (August 23, 2017) diff --git a/plugins/provisioners/ansible/provisioner/base.rb b/plugins/provisioners/ansible/provisioner/base.rb index 8e52d751f..78f6e40f1 100644 --- a/plugins/provisioners/ansible/provisioner/base.rb +++ b/plugins/provisioners/ansible/provisioner/base.rb @@ -228,7 +228,7 @@ module VagrantPlugins end group_vars.each_pair do |gname, gmembers| - if defined_groups.include?(gname.sub(/:vars$/, "")) + if defined_groups.include?(gname.sub(/:vars$/, "")) || gname == "all:vars" inventory_groups += "\n[#{gname}]\n" + gmembers.join("\n") + "\n" end end diff --git a/test/unit/plugins/provisioners/ansible/provisioner_test.rb b/test/unit/plugins/provisioners/ansible/provisioner_test.rb index 4a68993db..458ceb3ac 100644 --- a/test/unit/plugins/provisioners/ansible/provisioner_test.rb +++ b/test/unit/plugins/provisioners/ansible/provisioner_test.rb @@ -396,6 +396,19 @@ VF expect(inventory_content).to include("[group3:vars]\nstringvar1=stringvalue1\nstringvar2=stringvalue2\n") }.and_return(default_execute_result) end + + it "adds 'all:vars' section to the generated inventory" do + config.groups = { + "all:vars" => { "var1" => "value1", "var2" => "value2" } + } + + expect(Vagrant::Util::Subprocess).to receive(:execute).with('ansible-playbook', any_args) { |*args| + inventory_content = File.read(generated_inventory_file) + + expect(inventory_content).to include("[all:vars]\nvar1=value1\nvar2=value2\n") + + }.and_return(default_execute_result) + end end describe "with host_key_checking option enabled" do