I have a requirement, where I want to provision several Virtual Machine's with machine specific SSL certificates (generated using machine's IP/Host Name) required by a Java application.
I can create these certificates with some names like QA-Machine01, Prod-Machine01 etc. in advance and can keep these in folder somewhere.
How can I make Vagrant to dynamically pick these certificates, takes it's name (QA-Machine01, Prod-Machine01) and provision VM with certificates name as Machine Name?
Vagrant files are ruby code so if you have all certs in a directory you may write a loop in your vagrant file from the Dir.glob to make a multimachine vagrantfile:
Example:
mnames = Dir.glob("/my/cert/store/*.crt")
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
mname.each do |filename|
hostname = File.basename(filename).gsub(File.extname(filename),'')
config.vm.define hostname do |box|
box.vm.hostname = "#{hostname}.my.domain"
[.. any configuration you wish ...]
box.vm.provision :chef_client do |chef|
chef.add_recipe "my_recipe"
[..chef conf for your case ...]
end
end
end
end
Then you can vagrant up
to create and provision all machines or call vagrant up QA-Machine01
for only the QA machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With