I am trying to use vagrant to create a VM  with an ansible provisioning of 
a static defined inventory. But I cannot see how ansible will know how to 
connect to the VM that has been created. All solutions I have seen so-far 
force me to hardcode the network configuration and align that  with the 
inventory:

I really want to use the static inventory files, as here we configure what 
ansible groups the machine is a part of. 

The following example works when I hardcode the value for ansible_ssh_port; 
but I cannot find a way to discover it and given that vagrant will do 
vagrant automatic port conflict discovery and avoidance; I don't know how I 
can work around it?

Vagrant.require_version ">= 1.7.0"

Vagrant.configure(2) do |config|

  config.vm.box = "ubuntu/trusty64"

  config.vm.define "example_server" # This is the fixed name in the host 
file and is referenced by playbooks

  config.vm.provider "virtualbox" do |v|
   v.memory = 8192
   v.cpus = 4
 end

  config.ssh.forward_agent = true

  # Setup the Deployment user
 config.vm.provision "deployuser", type: "ansible" do |ansible|
   ansible.verbose = "v"
   ansible.playbook = "add_deployment_user.yml"
   ansible.inventory_path = "inventories/example.hosts"
   ansible.extra_vars = {
     ansible_ssh_host: "127.0.0.1",
     ansible_ssh_port: config.ssh.port
   }
 end
end





-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
--- 
You received this message because you are subscribed to the Google Groups 
"Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vagrant-up/e40c9540-eb42-4539-ab24-aa25852fbc1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to