Merge pull request #3628 from gildegoma/ansible-show-cmd
provisioners/ansible: show ansible-playbook in use
This commit is contained in:
commit
925eb47cb7
|
@ -66,6 +66,8 @@ module VagrantPlugins
|
||||||
# Support Multiple SSH keys and SSH forwarding:
|
# Support Multiple SSH keys and SSH forwarding:
|
||||||
env["ANSIBLE_SSH_ARGS"] = ansible_ssh_args unless ansible_ssh_args.empty?
|
env["ANSIBLE_SSH_ARGS"] = ansible_ssh_args unless ansible_ssh_args.empty?
|
||||||
|
|
||||||
|
show_ansible_playbook_command(env, command) if config.verbose
|
||||||
|
|
||||||
# Write stdout and stderr data, since it's the regular Ansible output
|
# Write stdout and stderr data, since it's the regular Ansible output
|
||||||
command << {
|
command << {
|
||||||
:env => env,
|
:env => env,
|
||||||
|
@ -213,6 +215,30 @@ module VagrantPlugins
|
||||||
def as_array(v)
|
def as_array(v)
|
||||||
v.kind_of?(Array) ? v : [v]
|
v.kind_of?(Array) ? v : [v]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show_ansible_playbook_command(env, command)
|
||||||
|
shell_command = ''
|
||||||
|
env.each_pair do |k, v|
|
||||||
|
if k == 'ANSIBLE_SSH_ARGS'
|
||||||
|
shell_command += "#{k}='#{v}' "
|
||||||
|
else
|
||||||
|
shell_command += "#{k}=#{v} "
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
shell_arg = []
|
||||||
|
command.each do |arg|
|
||||||
|
if arg =~ /(--start-at-task|--limit)=(.+)/
|
||||||
|
shell_arg << "#{$1}='#{$2}'"
|
||||||
|
else
|
||||||
|
shell_arg << arg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
shell_command += shell_arg.join(' ')
|
||||||
|
|
||||||
|
@machine.env.ui.detail(shell_command)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -226,6 +226,12 @@ VF
|
||||||
expect(args.length).to be > 0
|
expect(args.length).to be > 0
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not show the ansible-playbook command" do
|
||||||
|
expect(machine.env.ui).not_to receive(:detail).with { |full_command|
|
||||||
|
expect(full_command).to include("ansible-playbook")
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with groups option" do
|
describe "with groups option" do
|
||||||
|
@ -459,11 +465,30 @@ VF
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "with verbose option" do
|
||||||
|
before do
|
||||||
|
config.verbose = 'v'
|
||||||
|
end
|
||||||
|
|
||||||
|
it_should_set_arguments_and_environment_variables 6
|
||||||
|
it_should_set_optional_arguments({ "verbose" => "-v" })
|
||||||
|
|
||||||
|
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} -v playbook.yml")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Note:
|
# Note:
|
||||||
# The Vagrant Ansible provisioner does not validate the coherency of argument combinations,
|
# The Vagrant Ansible provisioner does not validate the coherency of argument combinations,
|
||||||
# and let ansible-playbook complain.
|
# and let ansible-playbook complain.
|
||||||
describe "with a maximum of options" do
|
describe "with a maximum of options" do
|
||||||
before do
|
before do
|
||||||
|
# vagrant general options
|
||||||
|
ssh_info[:forward_agent] = true
|
||||||
|
ssh_info[:private_key_path] = ['/my/key1', '/my/key2']
|
||||||
|
|
||||||
# command line arguments
|
# command line arguments
|
||||||
config.extra_vars = "@#{existing_file}"
|
config.extra_vars = "@#{existing_file}"
|
||||||
config.sudo = true
|
config.sudo = true
|
||||||
|
@ -505,6 +530,12 @@ VF
|
||||||
expect(args).to include("--why-not")
|
expect(args).to include("--why-not")
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "shows the ansible-playbook command, with additional quotes when required" do
|
||||||
|
expect(machine.env.ui).to receive(:detail).with { |full_command|
|
||||||
|
expect(full_command).to eq("ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=true PYTHONUNBUFFERED=1 ANSIBLE_SSH_ARGS='-o IdentityFile=/my/key2 -o ForwardAgent=yes -o ControlMaster=no -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --private-key=/my/key1 --user=testuser --connection=ssh --why-not --su-user=foot --ask-su-pass --limit='all' --inventory-file=#{generated_inventory_dir} --extra-vars=@#{File.expand_path(__FILE__)} --sudo --sudo-user=deployer -vvv --ask-sudo-pass --ask-vault-pass --vault-password-file=#{File.expand_path(__FILE__)} --tags=db,www --skip-tags=foo,bar --limit='machine*:&vagrant:!that_one' --start-at-task='an awesome task' playbook.yml")
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue