From 44f423b2be103b952f4066a165d679b80b0ce130 Mon Sep 17 00:00:00 2001 From: Pekka Helenius <35750356+Fincer-altego@users.noreply.github.com> Date: Mon, 23 Apr 2018 17:35:27 +0300 Subject: [PATCH] Add Vagrantfile for setting up multiple Salt minions --- scripts/vagrant_salt-minions/Vagrantfile | 87 ++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 scripts/vagrant_salt-minions/Vagrantfile diff --git a/scripts/vagrant_salt-minions/Vagrantfile b/scripts/vagrant_salt-minions/Vagrantfile new file mode 100644 index 0000000..c241cef --- /dev/null +++ b/scripts/vagrant_salt-minions/Vagrantfile @@ -0,0 +1,87 @@ +# Create multiple virtual machines with Vagrant on Linux +# Author: Pekka Helenius (~Fincer), 2018 + +####################################### +# Basic Vagrantfile configuration + +# Number of virtual machines +vbox_num = 2 + +# Virtual machine name prefix +vbox_prefix = "minion_" + +# Allocated memory per virtual machine +# NOTE: Remember the RAM limits of your host machine! +vbox_mem = 512 + +# CPU's per virtual machine +vbox_cpu = 1 + +# Vagrant box template for virtual machines +# +# If you change this, remember to check for salt file locations & +# package manager commands used in this Vagrantfile +# +# For more templates, see: https://app.vagrantup.com/boxes/search +vbox_template = "debian/jessie64" + +####################################### +# Create a new array for virtual machines + +vboxes = [] + +(1..vbox_num).each do |vbox| + vboxes.push("#{vbox_prefix}#{vbox}") +end + +####################################### +VAGRANT_API_VERSION = 2 + +####################################### +# This is for salt_install provision below + +initial_setup = " +# Start of $initial_setup variable + +apt-get update && \ +apt-get -y install salt-minion && \ +systemctl enable salt-minion + + if [ $? -ne 0 ]; then + exit 1 + fi + +# End of $initial_setup variable +" + +####################################### +# Define Vagrant machine configuration here + +Vagrant.configure(VAGRANT_API_VERSION) do |config| + + config.vm.box = "#{vbox_template}" + config.vm.box_check_update = true + config.vm.synced_folder ".", "/vagrant", disabled: true + + vboxes.each do |box| + config.vm.define "#{box}" do |node| + + node.vm.provision "salt_install", run: "once", type: "shell" do |cmd_1| + cmd_1.inline = "#{initial_setup}" + cmd_1.privileged = "true" + end + + node.vm.provision "salt_config", run: "once", type: "shell" do |cmd_2| + cmd_2.inline = "echo 'master: #{`hostname`}id: #{box}' | tee -a /etc/salt/minion && systemctl restart salt-minion" + cmd_2.privileged = "true" + end + + node.vm.provider "virtualbox" do |v| + v.memory = "#{vbox_mem}" + v.cpus = "#{vbox_cpu}" + v.name = "#{box}" + end + + end + end +end