diff --git a/plugins/provisioners/ansible/provisioner.rb b/plugins/provisioners/ansible/provisioner.rb index 8891f0357..557ec47b5 100644 --- a/plugins/provisioners/ansible/provisioner.rb +++ b/plugins/provisioners/ansible/provisioner.rb @@ -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