diff --git a/plugins/provisioners/ansible/provisioner/base.rb b/plugins/provisioners/ansible/provisioner/base.rb index a2533ea9c..abf24bbe7 100644 --- a/plugins/provisioners/ansible/provisioner/base.rb +++ b/plugins/provisioners/ansible/provisioner/base.rb @@ -388,6 +388,7 @@ gathered version stdout version: ansible_version_pattern = first_line.match(/(^ansible\s+)(.+)$/) if ansible_version_pattern _, @gathered_version, _ = ansible_version_pattern.captures + @gathered_version.strip! if @gathered_version @gathered_version_major = @gathered_version.match(/(\d)\..+$/).captures[0].to_i end diff --git a/test/unit/plugins/provisioners/ansible/provisioner_test.rb b/test/unit/plugins/provisioners/ansible/provisioner_test.rb index 318ad0f19..180f26869 100644 --- a/test/unit/plugins/provisioners/ansible/provisioner_test.rb +++ b/test/unit/plugins/provisioners/ansible/provisioner_test.rb @@ -984,6 +984,16 @@ VF end end + describe "whitespace in version string" do + before do + allow(subject).to receive(:gather_ansible_version).and_return("ansible #{config.version} \n...\n") + end + + it "sets the correct gathered_version" do + expect(Vagrant::Util::Subprocess).to receive(:execute).with('ansible-playbook', any_args).and_return(default_execute_result) + end + end + describe "and there is an ansible version mismatch" do before do allow(subject).to receive(:gather_ansible_version).and_return("ansible 1.9.6\n...\n")