Generate ansible_hosts file if one is not provided

This commit is contained in:
Collin Allen 2013-07-06 23:47:37 -07:00
parent e1e57024dc
commit f67938249d
1 changed files with 15 additions and 2 deletions

View File

@ -3,10 +3,10 @@ module VagrantPlugins
class Provisioner < Vagrant.plugin("2", :provisioner)
def provision
ssh = @machine.ssh_info
inventory_file_path = self.setup_inventory_file
options = %W[--private-key=#{ssh[:private_key_path]} --user=#{ssh[:username]}]
options << "--extra-vars=" + config.extra_vars.map{|k,v| "#{k}=#{v}"}.join(' ') if config.extra_vars
options << "--inventory-file=#{config.inventory_file}" if config.inventory_file
options << "--inventory-file=#{inventory_file_path}"
options << "--ask-sudo-pass" if config.ask_sudo_pass
if config.limit
@ -40,6 +40,19 @@ module VagrantPlugins
raise Vagrant::Errors::AnsiblePlaybookAppNotFound
end
end
def setup_inventory_file()
if config.inventory_file
return config.inventory_file
end
ssh = @machine.ssh_info
generated_inventory_file = "vagrant_ansible_inventory_#{machine.name}"
File.open(generated_inventory_file, 'w') do |file|
file.write("# Generated by Vagrant\n\n")
file.write("#{machine.name} ansible_ssh_host=#{ssh[:host]} ansible_ssh_port=#{ssh[:port]}\n")
end
return generated_inventory_file
end
end
end
end