test: add basic functionality
This commit is contained in:
parent
c65b579e16
commit
1fa4b3ed1a
3 changed files with 46 additions and 15 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
ansible-playbooks/
|
|
@ -1,22 +1,52 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
readonly CONFIG_ROOT="/srv/ansible"
|
||||
#readonly CONFIG_ROOT="/srv/ansible/playbooks"
|
||||
readonly CONFIG_ROOT="$PWD/ansible-playbooks"
|
||||
|
||||
function config_help() {
|
||||
echo "Printing config help"
|
||||
cat << EOF
|
||||
$(basename ${0}) config <command> [...]
|
||||
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() {
|
||||
echo "Pulling latest changes of repo"
|
||||
# git -C "$CONFIG_ROOT" pull
|
||||
}
|
||||
|
||||
# Executes an ansible-playbook on top.ansible.yml
|
||||
function config_full() {
|
||||
echo "Executing full playbook run"
|
||||
# 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() {
|
||||
echo "Executing single playbook"
|
||||
echo "Executing single playbook: $1"
|
||||
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
|
||||
echo "$newpath $([[ $debuglevel -eq 4 ]] && echo '-v') $([[ $dryrun -eq 1 ]] && echo '-C')"
|
||||
# ansible-playbook $([[ $debuglevel -eq 4 ]] && echo '-v') $([[ $dryrun -eq 1 ]] && echo '-C') "$newpath"
|
||||
}
|
||||
|
|
24
novos
24
novos
|
@ -13,22 +13,19 @@ done
|
|||
|
||||
# VARIABLES
|
||||
declare debuglevel=3
|
||||
declare dryrun=0
|
||||
|
||||
function usage() {
|
||||
cat << EOF
|
||||
usage: $(basename ${0}) <operation> [...]
|
||||
usage: $(basename ${0}) <operation> [command] ...
|
||||
operations:
|
||||
$(basename ${0}) {-h --help}
|
||||
$(basename ${0}) {-V --version}
|
||||
$(basename ${0}) {-v --verbose}
|
||||
$(basename ${0}) {--init} [servername] [network name]
|
||||
$(basename ${0}) {--datapack} [servername] [datapack dl url]
|
||||
$(basename ${0}) {--start} [servername] [port] (ip)
|
||||
$(basename ${0}) {--stop} [servername]
|
||||
$(basename ${0}) {--restart} [servername] [port] (ip)
|
||||
$(basename ${0}) {--attach} [servername]
|
||||
$(basename ${0}) {--reset} [servername]
|
||||
$(basename ${0}) {--delete} [servername]
|
||||
$(basename ${0}) {-n --dryrun}
|
||||
|
||||
commands:
|
||||
$(basename ${0}) config
|
||||
EOF
|
||||
}
|
||||
|
||||
|
@ -50,15 +47,17 @@ while true; do
|
|||
case "${1}" in
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
break
|
||||
;;
|
||||
-V|--version)
|
||||
version
|
||||
exit 0
|
||||
break
|
||||
;;
|
||||
-v|--verbose)
|
||||
debuglevel=4
|
||||
break
|
||||
;;
|
||||
-n|--dryrun)
|
||||
dryrun=1
|
||||
;;
|
||||
config)
|
||||
parent="$1"
|
||||
|
@ -80,3 +79,4 @@ while true; do
|
|||
esac
|
||||
shift
|
||||
done
|
||||
exit 0
|
||||
|
|
Loading…
Reference in a new issue