Generate ansible_hosts file if one is not provided
This commit is contained in:
parent
e1e57024dc
commit
f67938249d
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue