From eccb32a380a87ec5ff7712b30428a3a8cd316614 Mon Sep 17 00:00:00 2001 From: Aneesh Agrawal Date: Tue, 22 Dec 2015 07:12:07 -0500 Subject: [PATCH 1/2] Make Salt install/configure Vagrant 1.8 compatible 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](https://github.com/mitchellh/vagrant/pull/6474) was merged - [Another PR](https://github.com/mitchellh/vagrant/pull/6473) was not The second PR was rejected "in favor" of [a third PR](https://github.com/mitchellh/vagrant/pull/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. --- .travis.yml | 4 +-- .travis/configure_salt | 15 ----------- .travis/install_salt | 56 +++++++++++++++++++++++++++++++++------- .travis/setup_salt_roots | 12 +++++++++ Vagrantfile | 2 +- 5 files changed, 61 insertions(+), 28 deletions(-) delete mode 100755 .travis/configure_salt create mode 100755 .travis/setup_salt_roots diff --git a/.travis.yml b/.travis.yml index 08c19ead5..4011ec98f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/.travis/configure_salt b/.travis/configure_salt deleted file mode 100755 index 85dadcb44..000000000 --- a/.travis/configure_salt +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env sh - -configure_salt () { - set -o errexit - set -o nounset - - sudo mkdir -p /etc/salt - sudo cp .travis/minion /etc/salt/minion - - sudo mkdir -p /srv/salt - sudo cp -r . /srv/salt/states - sudo cp -r .travis/test_pillars /srv/salt/pillars -} - -configure_salt "$@" diff --git a/.travis/install_salt b/.travis/install_salt index 49d4d604a..cb2860aeb 100755 --- a/.travis/install_salt +++ b/.travis/install_salt @@ -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" @@ -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 [-F]] [--] os_name\n" + exit 1 +fi + +OS_NAME="$1" +install_salt + +if [ -n "${TEMPORARY_CONFIG_DIR}" ]; then + configure_salt +fi diff --git a/.travis/setup_salt_roots b/.travis/setup_salt_roots new file mode 100755 index 000000000..b7f24dc00 --- /dev/null +++ b/.travis/setup_salt_roots @@ -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 "$@" diff --git a/Vagrantfile b/Vagrantfile index dbfc7604e..01f2f9221 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -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 From 36b881ee53fe705ebf8c94290f160dc5645aa87f Mon Sep 17 00:00:00 2001 From: Aneesh Agrawal Date: Tue, 22 Dec 2015 08:16:30 -0500 Subject: [PATCH 2/2] Make getopt usage OS X compatible OS X does not use GNU getopt but rather BSD getopt, which is less friendly. Update getopt usage and argument parsing to be portable. --- .travis/install_salt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/install_salt b/.travis/install_salt index cb2860aeb..8d59a8d04 100755 --- a/.travis/install_salt +++ b/.travis/install_salt @@ -28,7 +28,7 @@ configure_salt () { sudo cp "${FORCE_FLAG}" -- "${TEMPORARY_CONFIG_DIR}/minion" /etc/salt/minion } -OPTIONS=$(getopt --options 'c:F' --name "$0" --shell sh -- "$@") +OPTIONS=$(getopt 'c:F' "$@") eval set -- "${OPTIONS}"