Skip to content

Instantly share code, notes, and snippets.

@renoirb
Last active December 10, 2021 16:53
Show Gist options
  • Save renoirb/6213834 to your computer and use it in GitHub Desktop.
Save renoirb/6213834 to your computer and use it in GitHub Desktop.
Using Vagrant with Salty-Vagrant and Multiple virtual machines
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.ssh.forward_agent = true
# Deployment instance salt master
config.vm.define :salt do |salt|
salt.vm.network :private_network, ip: "10.10.10.2"
salt.vm.hostname = 'master'
salt.vm.synced_folder "salt/roots/", "/srv/"
salt.vm.synced_folder "salt/key/", "/etc/salt/keys"
salt.vm.network :forwarded_port, guest: 22, host: 2220, auto_correct: true
salt.vm.provider "virtualbox" do |v|
v.name = "salt"
v.customize ["modifyvm", :id, "--memory", "1024"]
end
salt.vm.provision :salt do |config|
config.minion_config = "salt/minion"
config.master_config = "salt/master"
config.minion_key = "salt/key/minion.pem"
config.minion_pub = "salt/key/minion.pub"
config.master_key = "salt/key/master.pem"
config.master_pub = "salt/key/master.pub"
config.install_master = true
config.seed_master = {salt: "salt/key/master.pub", app0: "salt/key/minion.pub"}
config.run_highstate = false
config.accept_keys = true
config.verbose = true
config.bootstrap_options = "-D"
config.temp_config_dir = "/tmp"
end
end
# appX instance salt ninion
config.vm.define :app0 do |app0|
app0.vm.network :private_network, ip: "10.10.10.3"
app0.vm.hostname = "app0"
app0.vm.synced_folder "salt/key/", "/etc/salt/keys"
app0.vm.network :forwarded_port, guest: 22, host: 2221, auto_correct: true
app0.vm.provider "virtualbox" do |v|
v.name = "app0"
v.customize ["modifyvm", :id, "--memory", "1024"]
end
app0.vm.provision :salt do |config|
config.minion_config = "salt/minion"
config.minion_key = "salt/key/minion.pem"
config.minion_pub = "salt/key/minion.pub"
config.verbose = true
config.bootstrap_options = "-D"
config.temp_config_dir = "/tmp"
end
end
end

Description

Have you ever wanted to have a Vagrant workspace with more than one Virtual Machine, and managed by Salt Stack? I did, but the documentation is not all there yet.

I managed to make it work with the following, hope it will be useful.

To use

See the Complete salty-vagrant setup, but use the current Vagrantfile to have two machines.

Files in the workspace

Set the following files in your workspace, at the root of your web development project.

  • projectDir/Vagrantfile: The Vagrantfile from this gist
  • projectDir/salt/key: A few pem and pub files
  • projectDir/salt/roots: Checkout a few salt states as needed
  • projectDir/master: Salt master config, generally default do
  • projectDir/minion: Salt minion config, if master is called salt, no need to edit.

References

@mixja
Copy link

mixja commented Jan 4, 2015

You need to remove the synched folder configuration to /etc/salt/keys:

salt.vm.synced_folder "salt/key/", "/etc/salt/keys"
app0.vm.synced_folder "salt/key/", "/etc/salt/keys"

If you leave these options in place, the salt-master installation modifies permissions on /etc/salt/keys which then prevents the minion from being able to access this shared folder (at least for me when using NFS as the shared folder method given all of the issues with VMWare/HGFS synched folders)

@oliver-dungey
Copy link

Thanks for the very handy example. Is config.accept_keys = true still valid? I've just tried a similar approach without it and the minions keys had already been accepted by virtue of the seed_master directive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment