#!/usr/bin/env bash readonly CONFIG_ROOT="/srv/ansible/playbooks" function config_help() { cat << EOF $(basename ${0}) config [...] commands: $(basename ${0}) config help $(basename ${0}) config pull $(basename ${0}) config full $(basename ${0}) config single [playbook] EOF } # Pulls all ansible playbooks from the remote git repo function config_pull() { git -C "$CONFIG_ROOT" pull } # Executes an ansible-playbook on top.ansible.yml function config_full() { ansible-playbook $([[ $debuglevel -eq 4 ]] && echo '-v') $([[ $dryrun -eq 1 ]] && echo '-C') "${CONFIG_ROOT}/top.ansible.yml" } # Execute on a single playbook ansible-playbook function config_single() { local path="$CONFIG_ROOT/${1/\./\/}" # replace dots in path with forward-slashes local newpath="$path" # set $newpath to $path for later checking # Check if $path is a directory => add init.ansible.yml if [[ -d "$path" ]]; then newpath="$path/init.ansible.yml" fi # Check if $path is a file => add .ansible.yml if [[ -f "${path}.ansible.yml" ]]; then newpath="${path}.ansible.yml" fi # Check if original $path still matches with $newpath => Fail due to unknown module if [[ "$path" == "$newpath" ]]; then echo "Module '$1' not found" exit 1 fi ansible-playbook $([[ $debuglevel -eq 4 ]] && echo '-v') $([[ $dryrun -eq 1 ]] && echo '-C') "$newpath" }