Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provision a VM using Vagrant, Chef and/or Puppet with machine specific SSL certificate?

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?

like image 590
Vishal Bhatt Avatar asked Apr 20 '15 10:04

Vishal Bhatt


1 Answers

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.

like image 69
Tensibai Avatar answered Sep 23 '22 20:09

Tensibai