Skip to content

Commit

Permalink
Make Salt install/configure Vagrant 1.8 compatible
Browse files Browse the repository at this point in the history
The original Vagrantfile was meant to be used with Vagrant 1.7.4, but
required 2 patches to Vagrant for proper functionality, which I had
submitted as pull requests. Vagrant has since released a new version,
1.8.0, which has updates the Salt provisioner. PR status:
 - [One PR](hashicorp/vagrant#6474) was merged
 - [Another PR](hashicorp/vagrant#6473) was not

The second PR was rejected "in favor" of [a third
PR](hashicorp/vagrant#6073) which simply removed
the config_dir option entirely instead of using sudo to be able to write
in a priveleged directory. [An unrelated
PR](https://github.com/mitchellh/vagrant/pull/6382/files) removed a
second option we had been using: install_command.

These changes in Vagrant were due to incompabilities with the official
Salt bootstrap script, so this commit brings the install_salt script's
behavior closer to that of the official Salt bootstrap script as well.
Namely, it can now copy over configuration files as part of
installation, using the same flags as the official script.

The configure_salt script is now used just to setup the salt and pillar
roots on Travis (this is accomplished via shared folders in Vagrant),
hence the renaming.

With this commit and the new Vagrant version, the included Vagrantfile
now works with a vanilla Vagrant 1.8.0 install, no patching needed.
  • Loading branch information
aneeshusa committed Dec 22, 2015
1 parent 3e374be commit eccb32a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ matrix:
dist: trusty

before_install:
- .travis/install_salt "${TRAVIS_OS_NAME}"
- .travis/install_salt -F -c .travis -- "${TRAVIS_OS_NAME}"

install:
- .travis/configure_salt
- .travis/setup_salt_roots

# For debugging, check the grains reported by the Travis builder
- sudo salt-call --id="${SALT_NODE_ID}" grains.items
Expand Down
15 changes: 0 additions & 15 deletions .travis/configure_salt

This file was deleted.

56 changes: 46 additions & 10 deletions .travis/install_salt
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
#!/usr/bin/env sh

install_salt () {
set -o errexit
set -o nounset

if [ "$#" -lt 1 ]; then
printf >&2 "usage: $0 os_name\n"
exit 1
fi
OS_NAME="$1"
set -o errexit
set -o nounset

install_salt () {
# Ensure that pinned versions match as closely as possible
if [ "${OS_NAME}" = "linux" ]; then
printf "$0: installing salt for Linux\n"
Expand All @@ -28,4 +22,46 @@ install_salt () {
fi
}

install_salt "$@"
configure_salt () {
printf "$0: copying Salt minion configuration from ${TEMPORARY_CONFIG_DIR}\n"
sudo mkdir -p /etc/salt
sudo cp "${FORCE_FLAG}" -- "${TEMPORARY_CONFIG_DIR}/minion" /etc/salt/minion
}

OPTIONS=$(getopt --options 'c:F' --name "$0" --shell sh -- "$@")

eval set -- "${OPTIONS}"

TEMPORARY_CONFIG_DIR=""
FORCE_FLAG=""
OS_NAME=""

while true; do
case "$1" in
-c)
shift
TEMPORARY_CONFIG_DIR="$1"
shift
;;
-F)
FORCE_FLAG="-f"
shift
;;
--)
shift
break
;;
esac
done

if [ "$#" -lt 1 ]; then
printf >&2 "usage: $0 [-c <config_dir> [-F]] [--] os_name\n"
exit 1
fi

OS_NAME="$1"
install_salt

if [ -n "${TEMPORARY_CONFIG_DIR}" ]; then
configure_salt
fi
12 changes: 12 additions & 0 deletions .travis/setup_salt_roots
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh

set -o errexit
set -o nounset

setup_salt_roots () {
sudo mkdir -p /srv/salt
sudo cp -r . /srv/salt/states
sudo cp -r .travis/test_pillars /srv/salt/pillars
}

setup_salt_roots "$@"
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Vagrant.configure(2) do |config|
machine.vm.synced_folder File.join(dir, ".travis/test_pillars"), pillar_root
machine.vm.provision :salt do |salt|
salt.bootstrap_script = '.travis/install_salt'
salt.install_command = node[:os] # Pass OS type to install_salt script
salt.install_args = node[:os] # Pass OS type to install_salt script
salt.masterless = true
salt.minion_config = '.travis/minion'
# hack to provide additional options to salt-call
Expand Down

0 comments on commit eccb32a

Please sign in to comment.