Skip to content

Commit

Permalink
Update install-puppet-modules.sh to support Packer
Browse files Browse the repository at this point in the history
The script was better suited for the Vagrant use-case where source code
(Puppetfile etc) could be assumed to be present on the node running the script.
This is not generally the case with Packer.

Signed-off-by: Samuli Seppänen <[email protected]>
  • Loading branch information
Samuli Seppänen committed Jul 22, 2020
1 parent c0373c9 commit 718b641
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ systems. In this context bootstrapping means getting the node to a state where a
real configuration management system (e.g. Puppet) can take over it's
configuration.

These scripts are particularly useful with tools such as Vagrant for
provisioning virtual machines.
These scripts are particularly useful with tools such as Vagrant, Packer or
Terraform for provisioning virtual machines.

These scripts can be run standalone for the most part. One strategy is to
distribute a single site-specific initialization script that fetches and runs
Expand Down
28 changes: 26 additions & 2 deletions bootstrap/linux/install-puppet-modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
set -e

usage() {
echo "Usage: install-puppet-modules.sh [-n <modulename>] [-f <puppetfile>] [-r <moduleroot>] [-m <moduledir>] [-h]"
echo "Usage: install-puppet-modules.sh [-u <repo url>] [ -c <commit id> ] [-n <modulename>] [-f <puppetfile>] [-r <moduleroot>] [-m <moduledir>] [-h]"
echo
echo "Options:"
echo " -n module for which these dependencies are installed (no default value)"
echo " -u URL of the git repository that has the Puppetfile (default: \"\")"
echo " -c commit ID of the above repository (default: \"\")"
echo " -f path to Puppetfile (default: /vagrant/Puppetfile)"
echo " -r path to module root (default: /vagrant)"
echo " -m the directory to install modules to (default: /vagrant/modules)"
Expand All @@ -22,14 +24,18 @@ usage() {

# Default settings suitable for most Vagrant environments
MODULENAME=""
REPOURL=""
COMMIT=""
PUPPETFILE="/vagrant/Puppetfile"
MODULEROOT="/vagrant"
MODULEDIR="/vagrant/modules"

while getopts 'n:p:r:m:h' arg
while getopts 'n:u:c:p:r:m:h' arg
do
case $arg in
n) MODULENAME=$OPTARG ;;
u) REPOURL=$OPTARG ;;
c) COMMIT=$OPTARG ;;
p) PUPPETFILE=$OPTARG ;;
r) MODULEROOT=$OPTARG ;;
m) MODULEDIR=$OPTARG ;;
Expand All @@ -55,6 +61,23 @@ install_r10k() {
puppet resource package r10k ensure=present provider=puppet_gem
}

clone_repo() {
CLONE_CWD=`pwd`

if ! [ "$REPOURL" = "" ]; then
git clone -n $REPOURL $MODULEROOT
cd $MODULEROOT

if [ "$COMMIT" = "" ]; then
git checkout master
else
git checkout $COMMIT
fi
fi

cd $CLONE_CWD
}

install_modules() {
PUPPETFILE=$1
MODULEDIR=$2
Expand All @@ -69,5 +92,6 @@ add_root_module_link() {

install_git
install_r10k
clone_repo
install_modules $PUPPETFILE $MODULEDIR
add_root_module_link $MODULEROOT $MODULENAME

0 comments on commit 718b641

Please sign in to comment.