provisioners/ansible: prefer ssh '-i' argument
In cd93721
, I relied on a suprising combination of quotes to protect ssh
execution to strip the quoted path to the private key file.
Since any ssh command line argument can be passed via
`ANSIBLE_SSH_ARGS`, it is quite more readable and easy to rely on the
`-i` argument, which is not affected like `-o IdentityFile=...` and also
supports multiple occurences.
See also http://sourceforge.net/p/fuse/mailman/message/30498048/
Finally fix #6671
Note that I decided to not squash both commits for better
documentation and traceability.
This commit is contained in:
parent
cd93721f8f
commit
ddbd2a4cfc
|
@ -129,8 +129,8 @@ BUG FIXES:
|
|||
[GH-6586, GH-6552]
|
||||
- provisioners/ansible: use quotes for the `ansible_ssh_private_key_file`
|
||||
value in the generated inventory [GH-6209]
|
||||
- provisioners/ansible: use quotes for the IdentityFile OpenSSH command line
|
||||
arguments [GH-6671]
|
||||
- provisioners/ansible: use quotes when passing the private key files via
|
||||
OpenSSH `-i` command line arguments [GH-6671]
|
||||
- provisioners/ansible: don't show the `ansible-playbook` command when verbose
|
||||
option is an empty string
|
||||
- provisioners/chef: fix `nodes_path` for Chef Zero [GH-6025, GH-6049]
|
||||
|
|
|
@ -229,9 +229,7 @@ module VagrantPlugins
|
|||
# Multiple Private Keys
|
||||
unless !config.inventory_path && @ssh_info[:private_key_path].size == 1
|
||||
@ssh_info[:private_key_path].each do |key|
|
||||
# The outer single quotes are required to protect the inner
|
||||
# double quotes to be stripped by the ssh/shell execution.
|
||||
ssh_options << "-o IdentityFile='\"#{key}\"'"
|
||||
ssh_options << "-i '#{key}'"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -604,8 +604,8 @@ VF
|
|||
it "passes additional Identity Files via ANSIBLE_SSH_ARGS" do
|
||||
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
|
||||
cmd_opts = args.last
|
||||
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile='\"/an/other/identity\"'")
|
||||
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile='\"/yet/an/other/key\"'")
|
||||
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-i '/an/other/identity'")
|
||||
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-i '/yet/an/other/key'")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -786,7 +786,7 @@ VF
|
|||
|
||||
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("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=true ANSIBLE_SSH_ARGS='-o IdentitiesOnly=yes -o IdentityFile='\"/my/key1\"' -o IdentityFile='\"/my/key2\"' -o ForwardAgent=yes -o ControlMaster=no -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --ask-sudo-pass --ask-vault-pass --limit='machine*:&vagrant:!that_one' --inventory-file=#{generated_inventory_dir} --extra-vars=@#{File.expand_path(__FILE__)} --sudo --sudo-user=deployer -vvv --vault-password-file=#{File.expand_path(__FILE__)} --tags=db,www --skip-tags=foo,bar --start-at-task='an awesome task' --why-not --su-user=foot --ask-su-pass --limit='all' --private-key=./myself.key playbook.yml")
|
||||
expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=true ANSIBLE_SSH_ARGS='-o IdentitiesOnly=yes -i '/my/key1' -i '/my/key2' -o ForwardAgent=yes -o ControlMaster=no -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --ask-sudo-pass --ask-vault-pass --limit='machine*:&vagrant:!that_one' --inventory-file=#{generated_inventory_dir} --extra-vars=@#{File.expand_path(__FILE__)} --sudo --sudo-user=deployer -vvv --vault-password-file=#{File.expand_path(__FILE__)} --tags=db,www --skip-tags=foo,bar --start-at-task='an awesome task' --why-not --su-user=foot --ask-su-pass --limit='all' --private-key=./myself.key playbook.yml")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue