How to specify an environment for salt’s top.sls file from Vagrant

saltstackvagrant

I want to use Vagrant to deploy a range of boxes with salt.

I've looked through all the available Vagrant salt options available in salty-vagrant (now built in) and I can't see any that would let me specify which "environment" to use, as referenced in salt.sls

dev:
  'webserver*dev*':
    - webserver
  'db*dev*':
    - db
qa:
  'webserver*qa*':
    - webserver
  'db*qa*':
    - db

I want to be able to have the same salt directory for all my machine types, and use different Vagrant files (or even parameters to vagrant) to determine whether I'm building a dev box, a qa box, a db box, etc.

Is there any way to pass this information from Vagrant to salt?

Best Answer

The easiest way to pass information to the minion in Vagrant is the minon file. You can define grains in the minion file, but also the ID of the minon.

I set up a set of Vagrant boxes myself using the following approach. Here some excerpts:

# top.sls (excerpt)
base:
  'webserver*':
    - webserver
  'db*':
    - db

In this example the webserver* and db* entries are the host names. I found that Vagrant sets up the hostname of the box very late (at least when I tried it), so I passed a minon file with the hard coded minon name in vagrant:

# Vagrantfile (excerpt)
config.vm.synced_folder "salt/roots/", "/srv/"
config.vm.provision :salt do |salt|
  salt.minion_config = "salt/minion"
  salt.run_highstate = true
end

And the minion file:

# minion (excerpt)
id: webservertest

You can also define grain information in the minion file.

I hope this helps.

Br, Alexander.

Related Topic