From c73da78ee941c771339625ae58846242133a4f57 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sun, 8 Dec 2019 14:07:24 +0100 Subject: [PATCH] Initial import --- .gitignore | 1 + README.md | 7 +++ Vagrantfile | 68 +++++++++++++++++++++++++ saltstack/config/master | 14 +++++ saltstack/config/minion-1 | 2 + saltstack/config/minion-2 | 2 + saltstack/config/minion-master | 2 + saltstack/pillar/test/data.sls | 7 +++ saltstack/pillar/top.sls | 3 ++ saltstack/salt/test/files/test.template | 4 ++ saltstack/salt/test/init.sls | 21 ++++++++ saltstack/salt/top.sls | 6 +++ 12 files changed, 137 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 Vagrantfile create mode 100644 saltstack/config/master create mode 100644 saltstack/config/minion-1 create mode 100644 saltstack/config/minion-2 create mode 100644 saltstack/config/minion-master create mode 100644 saltstack/pillar/test/data.sls create mode 100644 saltstack/pillar/top.sls create mode 100644 saltstack/salt/test/files/test.template create mode 100644 saltstack/salt/test/init.sls create mode 100644 saltstack/salt/top.sls diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8000dd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vagrant diff --git a/README.md b/README.md new file mode 100644 index 0000000..750830d --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Vagrant based salt test environment + +This is a simple multi machine vagrant test environment. +It spins up one salt-master and two salt-minion machines, and creates a rough working salt skeleton environment on them for testing purposes. +Simply run `vagrant up` to spin everything up. + +In case you want to adjust the configuration, use `vagrant rsync` to refresh the files within the virtual machines. diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..92d6517 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,68 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + # Use this box as base for all machines + config.vm.box = "debian/buster64" + + + # Define primary salt-master vm + config.vm.define "salt-master", primary: true do |master| + master.vm.hostname = "salt-master" + # Define network for salt management + master.vm.network "private_network", ip: "10.254.254.2", virtualbox__intnet: "salt-management" + + # Sync salt pillar + state files here + master.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__exclude: [".git/",] + + # Provide dependencies (also for gitfs) + master.vm.provision :shell, :inline => "sudo apt-get -y install git-core python3-pygit2 python3-setuptools python3-tornado" + + # Symlink states + pillar to /srv + master.vm.provision :shell, :inline => "ln -s /vagrant/saltstack/salt /srv/" + master.vm.provision :shell, :inline => "ln -s /vagrant/saltstack/pillar /srv/" + + # Use vagrant salt provisioner (uses most recent salt-bootstrap script) + # See https://www.vagrantup.com/docs/provisioning/salt.html + master.vm.provision :salt do |salt| + salt.bootstrap_options = '-F -c /tmp/ -P -x python3' + salt.colorize = true + salt.install_master = true + salt.minion_config = "saltstack/config/minion-master" + salt.master_config = "saltstack/config/master" + salt.verbose = true + end + + master.vm.provision :shell, :inline => "echo salt-master is up!" + master.vm.provision :shell, :inline => "ip addr show" + + end # config.vm.define "salt-master" + + + + # Define two salt-minion vms + (1..2).each do |i| + config.vm.define "salt-minion-#{i}" do |minion| + minion.vm.hostname = "salt-minion-#{i}" + + # Define network for salt management + minion.vm.network "private_network", ip: "10.254.254.2#{i}", virtualbox__intnet: "salt-management" + + # Use vagrant salt provisioner (uses most recent salt-bootstrap script) + # See https://www.vagrantup.com/docs/provisioning/salt.html + minion.vm.provision :salt do |salt| + salt.bootstrap_options = '-F -c /tmp/ -P -x python3' + salt.colorize = true + salt.install_master = false + salt.masterless = false + salt.minion_config = "saltstack/config/minion-#{i}" + salt.verbose = true + end + + minion.vm.provision :shell, :inline => "echo salt-minion #{i} is up!" + minion.vm.provision :shell, :inline => "ip addr show" + end # config.vm.define "salt-minion-#{i}" + + end # (1..2).each do |i| + +end # Vagrant.configure diff --git a/saltstack/config/master b/saltstack/config/master new file mode 100644 index 0000000..996c373 --- /dev/null +++ b/saltstack/config/master @@ -0,0 +1,14 @@ +interface: 10.254.254.2 + +auto_accept: True + +fileserver_backend: + - roots + +file_roots: + base: + - /srv/salt/ + +pillar_roots: + base: + - /srv/pillar diff --git a/saltstack/config/minion-1 b/saltstack/config/minion-1 new file mode 100644 index 0000000..6d8306d --- /dev/null +++ b/saltstack/config/minion-1 @@ -0,0 +1,2 @@ +id: 'minion-1' +master: 10.254.254.2 diff --git a/saltstack/config/minion-2 b/saltstack/config/minion-2 new file mode 100644 index 0000000..a52f4f0 --- /dev/null +++ b/saltstack/config/minion-2 @@ -0,0 +1,2 @@ +id: 'minion-2' +master: 10.254.254.2 diff --git a/saltstack/config/minion-master b/saltstack/config/minion-master new file mode 100644 index 0000000..bf6106f --- /dev/null +++ b/saltstack/config/minion-master @@ -0,0 +1,2 @@ +id: 'minion-master' +master: 10.254.254.2 diff --git a/saltstack/pillar/test/data.sls b/saltstack/pillar/test/data.sls new file mode 100644 index 0000000..d8d181d --- /dev/null +++ b/saltstack/pillar/test/data.sls @@ -0,0 +1,7 @@ +test: + foo: True + bar: is open + baz: + - first + - second + - third diff --git a/saltstack/pillar/top.sls b/saltstack/pillar/top.sls new file mode 100644 index 0000000..c76476f --- /dev/null +++ b/saltstack/pillar/top.sls @@ -0,0 +1,3 @@ +base: + '*': + - test.data diff --git a/saltstack/salt/test/files/test.template b/saltstack/salt/test/files/test.template new file mode 100644 index 0000000..1e34799 --- /dev/null +++ b/saltstack/salt/test/files/test.template @@ -0,0 +1,4 @@ +### THIS FILE IS MANAGED BY SALT STATE `test`. +### YOUR CHANGES WILL BE OVERWRITTEN! +{% set pillar = salt['pillar.get']('test') %} +{{ pillar.foo }} diff --git a/saltstack/salt/test/init.sls b/saltstack/salt/test/init.sls new file mode 100644 index 0000000..d7c5e96 --- /dev/null +++ b/saltstack/salt/test/init.sls @@ -0,0 +1,21 @@ +test_create_temp_file: + file.managed: + - name: /tmp/test.file + - mode: 0666 + - user: root + - group: root + - template: jinja + - contents: | + {% set pillar = salt['pillar.get']('test') %} + {{ pillar.foo }} + {{ pillar.bar }} + + +test_create_other_temp_file: + file.managed: + - name: /tmp/test2.file + - mode: 0444 + - user: root + - group: root + - template: jinja + - source: salt://test/files/test.template diff --git a/saltstack/salt/top.sls b/saltstack/salt/top.sls new file mode 100644 index 0000000..9e21296 --- /dev/null +++ b/saltstack/salt/top.sls @@ -0,0 +1,6 @@ +base: + 'salt-master': + - test + + 'minion-*': + - test