27 lines
759 B
Bash
27 lines
759 B
Bash
#!/usr/bin/env bash
|
|
|
|
readonly CONFIG_ROOT="/srv/ansible/playbooks"
|
|
|
|
|
|
function state_sls() {
|
|
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 $([[ $testmode -eq 1 ]] && echo '-C') -D "$newpath"
|
|
}
|