Skip to content

Instantly share code, notes, and snippets.

@q1x
Created November 11, 2020 20:19
Show Gist options
  • Save q1x/1ea07cebd9c45b2dc77c9f437f4e4314 to your computer and use it in GitHub Desktop.
Save q1x/1ea07cebd9c45b2dc77c9f437f4e4314 to your computer and use it in GitHub Desktop.
Vagrant Box for SaltStack Development
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "geerlingguy/centos7"
config.vm.network "docs", guest: 8000, host: 8000, host_ip: "127.0.0.1"
config.vm.provision "shell", inline: <<-SHELL
set -e
yum -q -y install git vim-enhanced @development zlib-devel bzip2 bzip2-devel readline-devel sqlite \
sqlite-devel openssl-devel xz xz-devel libffi-devel findutils
[[ -d /root/.pyenv ]] || git clone https://github.com/pyenv/pyenv.git /root/.pyenv
[[ -d /root/.pyenv/plugins/pyenv-virtualenv ]] || git clone https://github.com/pyenv/pyenv-virtualenv.git /root/.pyenv/plugins/pyenv-virtualenv
if ! grep -q 'export PATH="/root/.pyenv/bin:$PATH"' /root/.bashrc; then
echo 'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bashrc
fi
if ! grep -q 'eval "$(pyenv init -)"' /root/.bashrc; then
echo 'eval "$(pyenv init -)"' >> /root/.bashrc
fi
if ! grep -q 'eval "$(pyenv virtualenv-init -)"' /root/.bashrc; then
echo 'eval "$(pyenv virtualenv-init -)"' >> /root/.bashrc
fi
source /root/.bashrc
[[ -d /root/.pyenv/versions/3.7.0 ]] || pyenv install 3.7.0
[[ -d /root/.pyenv/versions/salt ]] || pyenv virtualenv 3.7.0 salt
pyenv activate salt
python -m pip install --upgrade pip
python -m pip install sphinx
python -m pip install pre-commit
python -m pip install nox
[[ -d /vagrant/salt ]] || git clone --depth=1 --origin salt https://github.com/saltstack/salt.git /vagrant/salt
cd /vagrant/salt
pre-commit install
python -m pip install -e .
mkdir -p /opt/salt/etc/salt/
mkdir -p /opt/salt/var/run/salt/{master,minion}/
cat <<EOF >/opt/salt/etc/salt/master
user: $(whoami)
root_dir: /opt/salt
#sock_dir: /var/run/salt/master
#publish_port: 5505
#ret_port: 5506
EOF
cat <<EOF >/opt/salt/etc/salt/minion
user: $(whoami)
root_dir: /opt/salt
#sock_dir: /var/run/salt/minion
master: localhost
id: saltdev
#master_port: 5506
EOF
cat <<EOF >/etc/motd
############################################################################
# #
# Welcome to SaltStack! #
# #
# Use 'sudo -s' to switch to the root user and switch to the #
# saltstack pyenv environment by issuing the following command: #
# #
# pyenv activate salt #
# #
# Have fun! #
# #
############################################################################
EOF
if [[ $(ps ax | grep salt-master | grep -cv grep) -gt 0 ]]; then
pkill salt-master
sleep 2
fi
salt-master --config-dir=/opt/salt/etc/salt/ --log-level=debug --daemon
if [[ $(ps ax | grep salt-minion | grep -cv grep) -gt 0 ]]; then
pkill salt-minion
sleep 2
fi
salt-minion --config-dir=/opt/salt/etc/salt/ --log-level=debug --daemon
sleep 2
if [[ $(ps ax | grep salt-master | grep -cv grep) -gt 0 ]] && [[ $(ps ax | grep salt-minion | grep -cv grep) -gt 0 ]]; then
salt-key -c /opt/salt/etc/salt/ -Ay
sleep 2
salt -c /opt/salt/etc/salt/ saltdev test.version
echo ""
echo "##################################################################################"
echo "### Salt is setup in /vagrant/salt. Please visit for further instructions, see ###"
echo "### https://github.com/waynew/salt/blob/improve-contributing-docs/HACKING.rst ###"
echo "##################################################################################"
fi
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment