Skip to content

Commit

Permalink
provisioners/ansible: Put ssh key in the inventory
Browse files Browse the repository at this point in the history
Vagrant 1.7.1 creates and injects new ssh keys for each virtual machine.
When it started ansible with the "parallel provisioning trick",
it would only send the ssh key of the targeted virtual machine.
With this change, vagrant now stores the ssh key for each virtual
machines directly in the generated ansible inventory, and thus allow
ansible parallelism.

Note that this change is not sufficient, as it would break vagrant
configuration based on a custom inventory (file or script). This issue
will be addressed in a next commit.

Signed-off-by: Luis Pabón <lpabon@redhat.com>
  • Loading branch information
Luis Pabón authored and gildegoma committed May 29, 2015
1 parent d7eaf50 commit 3d62a91
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions plugins/provisioners/ansible/provisioner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def provision
#

# Connect with Vagrant SSH identity
options = %W[--private-key=#{@ssh_info[:private_key_path][0]} --user=#{@ssh_info[:username]}]
options = %W[--user=#{@ssh_info[:username]}]

# Connect with native OpenSSH client
# Other modes (e.g. paramiko) are not officially supported,
Expand Down Expand Up @@ -118,7 +118,8 @@ def setup_inventory_file
m = @machine.env.machine(*am)
m_ssh_info = m.ssh_info
if !m_ssh_info.nil?
file.write("#{m.name} ansible_ssh_host=#{m_ssh_info[:host]} ansible_ssh_port=#{m_ssh_info[:port]}\n")
# Pass the private key generated for each VM to ansible
file.write("#{m.name} ansible_ssh_host=#{m_ssh_info[:host]} ansible_ssh_private_key_file=#{m_ssh_info[:private_key_path][0]} ansible_ssh_port=#{m_ssh_info[:port]}\n")
inventory_machines[m.name] = m
else
@logger.error("Auto-generated inventory: Impossible to get SSH information for machine '#{m.name} (#{m.provider_name})'. This machine should be recreated.")
Expand Down

0 comments on commit 3d62a91

Please sign in to comment.