From 1c884fa4e5a847549afa45350e37b0362c50feae Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Tue, 25 Nov 2014 08:12:43 +0100 Subject: [PATCH] provisioners/ansible: Show Ansible command when VAGRANT_LOG=debug --- CHANGELOG.md | 2 ++ plugins/provisioners/ansible/provisioner.rb | 2 +- .../provisioners/ansible/provisioner_test.rb | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3ac048b7..53565b085 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ IMPROVEMENTS: - providers/docker: `stop_timeout` can be used to modify the `docker stop` timeout. [GH-4504] - provisioners/chef: Automatically install Chef when using a Chef provisioner. + - provisioners/ansible: Always show Ansible command executed when Vagrant log + level is debug (even if ansible.verbose is false) - synced\_folders/nfs: Won't use `sudo` to write to /etc/exports if there are write privileges. [GH-2643] - synced\_folders/smb: Credentials from one SMB will be copied to the rest. [GH-4675] diff --git a/plugins/provisioners/ansible/provisioner.rb b/plugins/provisioners/ansible/provisioner.rb index 3de2cc3a4..e43c81a96 100644 --- a/plugins/provisioners/ansible/provisioner.rb +++ b/plugins/provisioners/ansible/provisioner.rb @@ -66,7 +66,7 @@ module VagrantPlugins # Support Multiple SSH keys and SSH forwarding: env["ANSIBLE_SSH_ARGS"] = ansible_ssh_args unless ansible_ssh_args.empty? - show_ansible_playbook_command(env, command) if config.verbose + show_ansible_playbook_command(env, command) if (config.verbose || @logger.debug?) # Write stdout and stderr data, since it's the regular Ansible output command << { diff --git a/test/unit/plugins/provisioners/ansible/provisioner_test.rb b/test/unit/plugins/provisioners/ansible/provisioner_test.rb index 45951e8b3..f93f1f53b 100644 --- a/test/unit/plugins/provisioners/ansible/provisioner_test.rb +++ b/test/unit/plugins/provisioners/ansible/provisioner_test.rb @@ -50,6 +50,8 @@ VF let(:generated_inventory_file) { File.join(generated_inventory_dir, 'vagrant_ansible_inventory') } before do + subject.instance_variable_get(:@logger).stub(:debug?).and_return(false) + machine.stub(ssh_info: ssh_info) machine.env.stub(active_machines: [[iso_env.machine_names[0], :dummy], [iso_env.machine_names[1], :dummy]]) @@ -465,6 +467,19 @@ VF end end + describe "with VAGRANT_LOG=debug, but without verbose option" do + before do + subject.instance_variable_get(:@logger).stub(:debug?).and_return(true) + config.verbose = false + end + + it "shows the ansible-playbook command" do + expect(machine.env.ui).to receive(:detail).with { |full_command| + expect(full_command).to eq("ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false PYTHONUNBUFFERED=1 ansible-playbook --private-key=/path/to/my/key --user=testuser --limit='machine1' --inventory-file=#{generated_inventory_dir} playbook.yml") + } + end + end + describe "with verbose option" do before do config.verbose = 'v'