Reputation: 33
I have to provision a bunch of development vagrantboxes installed on different physical computers (OS X, Win, Ubuntu) with Ansible. As long as all ansible playbooks/roles/templates are unified (prod, dev) and stored in git, using ansible-pull and dealing with prod configs and vault that stores a real passwords is not an option. So the idea is to make every vagrantbox to create a reverse ssh tunnel to some server where ansible-playbook will be applied to a range of ports. The question is: how to pick a free port from vagrantbox so I don't have to hardcode numbers to each VM created by developers? Another question: is there any other, less complicated way to provision vagrant VMs working on different OS?
Upvotes: 1
Views: 637
Reputation: 33
I found out that ssh automatically picks a free port if 0 is set as a port number. So running ssh -N -f -R 0:localhost:22 user@middle-server on my vagrant establishes a connection at the middle server where redirects localhost:port-picked to vagrant:22, and I can then apply ansible-playbook to a range of ports on middle server without copying playbooks to vagrant machines.
Upvotes: 1