vagrant ssh_port with ansible static inventory

119 views
Skip to first unread message

cmar...@aminocom.com

unread,
Dec 16, 2016, 11:31:37 AM12/16/16
to Vagrant
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





cmar...@aminocom.com

unread,
Dec 17, 2016, 6:52:37 PM12/17/16
to Vagrant
OK didn't get any feedback on this one yet; so I had a look at the source for Vagrant; it seemed reasonably easy to resolve so I have proposed the following pull-request:


Lets see if my proposal gets any traction.
Reply all
Reply to author
Forward
0 new messages