Point Ansible to SSH Key in Vagrantfile

tl;dr - Is there a way to use something like ansible.ssh\_key\_path = /path/to/ssh/key/for/environment?

Currently I'm working on a project that should enable me to create different Vagrantfiles based on which environment (production, testing, development) should be provisioned. I'm using Ansible to actually start the services needed on these machines (e.g. nginx, php, mysql). However, I thought it would be best to use different ssh keys for different environments. So: Production gets key A, Testing gets key B and Development gets key C. I only need to change certain variables in the Vagrantfile to achieve this.

Currently I have this piece of code:

web.vm.provision "ansible" do |ansible|
ansible.limit = "all"
ansible.inventory_path = inventory_file
ansible.playbook = nginx_playbook

The 'inventory\_file' and 'nginx\_playbook' are variables based on which production is being changed by the Vagrantfile.

Leave a Comment