Skip to content

Instantly share code, notes, and snippets.

@Mierdin
Created December 30, 2014 17:01
Show Gist options
  • Select an option

  • Save Mierdin/0f9e942e4dd85ea18def to your computer and use it in GitHub Desktop.

Select an option

Save Mierdin/0f9e942e4dd85ea18def to your computer and use it in GitHub Desktop.
A shell script to assemble a list of ansible roles from GitHub repos in my profile (for a big upcoming demonstration)
#!/bin/bash
set -euo pipefail # Unofficial bash strict mode
IFS=$'\n\t'
# This script will clone each GitHub repo containing a desired
# Ansible role, and extract the role contained within. Used to
# assemble a list of Ansible roles, specifically for demo purposes
# Create array containing repository names
declare -a REPOS=(
ansible-role-dnsmasq
ansible-role-quagga
ansible-role-iscdhcp
)
if [ ! -d ~/Code/ansiblemain ]; then
echo "Ansible working directory not found. Exiting."
exit
fi
cd ~/Code/ansiblemain
# Create roles dir if needed, and delete all existing roles
mkdir roles && rm -rf roles/*
# Create function to download repo
function dlrepo {
if [ -d "$1" ]; then
rm -rf $1
fi
git clone https://github.com/Mierdin/$1 tmpworkspace/$1
# Copy all subdirectories
cp -r tmpworkspace/$1/roles/* roles/
}
# Need to create a temp working dir if needed here
if [ -d "tmpworkspace" ]; then
rm -rf tmpworkspace
fi
mkdir tmpworkspace
# Loop through the array, cloning into working directory
for i in "${REPOS[@]}"
do
dlrepo $i
done
# Clean up temporary workspace
rm -rf tmpworkspace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment