From d1cecfe7a81f28885f6a94de91ab810f8ca22a0c Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 18 Feb 2017 13:29:18 +0100 Subject: [PATCH] Setup salt provisioning This commit performs salt provisioning setup by adding salt master to the salt VM and salt minion to all VMs. An /etc/hosts entry for the salt master is added using a shell provisioner. No salt executions are performed yet. --- Vagrantfile | 20 ++++++++++++++++++-- salt/minion | 1 + scripts/add_salt_to_etc_hosts.sh | 22 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 salt/minion create mode 100644 scripts/add_salt_to_etc_hosts.sh diff --git a/Vagrantfile b/Vagrantfile index a1b56f1..593c904 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,18 +6,34 @@ Vagrant.configure("2") do |config| config.vm.post_up_message = nil config.vm.synced_folder ".", "/vagrant", disabled: true + config.vm.provision "shell", + inline: "sed -i 's/^mesg n$/tty -s \\&\\& mesg n/g' /root/.profile" + config.vm.provision "shell", + path: "scripts/add_salt_to_etc_hosts.sh" + config.vm.provision :salt do |salt| + salt.masterless = false + salt.minion_config = "salt/minion" + salt.run_highstate = false + salt.install_type = "stable" + end + config.vm.define "salt" do |node| - node.vm.hostname = "salt" + node.vm.hostname = "salt.gva.dev" node.vm.synced_folder "repos/gvasalt/states", "/srv/salt" node.vm.synced_folder "repos/gvasalt/pillar", "/srv/pillar" node.vm.network "private_network", ip: "172.16.4.10" node.vm.provider "virtualbox" do |vb| vb.memory = "256" end + + node.vm.provision :salt do |salt| + salt.install_master = true + salt.minion_id = "salt" + end end config.vm.define "mq" do |node| - node.vm.hostname = "mq" + node.vm.hostname = "mq.gva.dev" node.vm.network "private_network", ip: "172.16.4.20" node.vm.provider "virtualbox" do |vb| vb.memory = "256" diff --git a/salt/minion b/salt/minion new file mode 100644 index 0000000..bebd8ef --- /dev/null +++ b/salt/minion @@ -0,0 +1 @@ +# empty minion config diff --git a/scripts/add_salt_to_etc_hosts.sh b/scripts/add_salt_to_etc_hosts.sh new file mode 100644 index 0000000..fd1bb74 --- /dev/null +++ b/scripts/add_salt_to_etc_hosts.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +set -e + +ip_address="172.16.4.10" +host_name="salt.gva.dev" + +matches_in_host="$(grep -n $host_name /etc/hosts | cut -f1 -d:)" +host_entry="${ip_address} ${host_name} salt" + +if [ ! -z "$matches_in_host" ] +then + echo "Updating existing hosts entry" + + echo $matches_in_host | while read -r line_number; do + sed -i "${line_number}s/.*/${host_entry}/" /etc/hosts + done +else + echo "Adding new hosts entry" + + echo "${host_entry}" >> /etc/hosts +fi