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
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
readonly CONFIG_ROOT="/srv/ansible"
|
#readonly CONFIG_ROOT="/srv/ansible/playbooks"
|
||||||
|
readonly CONFIG_ROOT="$PWD/ansible-playbooks"
|
||||||
|
|
||||||
function config_help() {
|
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
|
# Pulls all ansible playbooks from the remote git repo
|
||||||
function config_pull() {
|
function config_pull() {
|
||||||
echo "Pulling latest changes of repo"
|
echo "Pulling latest changes of repo"
|
||||||
|
# git -C "$CONFIG_ROOT" pull
|
||||||
}
|
}
|
||||||
|
|
||||||
# Executes an ansible-playbook on top.ansible.yml
|
# Executes an ansible-playbook on top.ansible.yml
|
||||||
function config_full() {
|
function config_full() {
|
||||||
echo "Executing full playbook run"
|
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
|
# Execute on a single playbook ansible-playbook
|
||||||
function config_single() {
|
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
|
# VARIABLES
|
||||||
declare debuglevel=3
|
declare debuglevel=3
|
||||||
|
declare dryrun=0
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
usage: $(basename ${0}) <operation> [...]
|
usage: $(basename ${0}) <operation> [command] ...
|
||||||
operations:
|
operations:
|
||||||
$(basename ${0}) {-h --help}
|
$(basename ${0}) {-h --help}
|
||||||
$(basename ${0}) {-V --version}
|
$(basename ${0}) {-V --version}
|
||||||
$(basename ${0}) {-v --verbose}
|
$(basename ${0}) {-v --verbose}
|
||||||
$(basename ${0}) {--init} [servername] [network name]
|
$(basename ${0}) {-n --dryrun}
|
||||||
$(basename ${0}) {--datapack} [servername] [datapack dl url]
|
|
||||||
$(basename ${0}) {--start} [servername] [port] (ip)
|
commands:
|
||||||
$(basename ${0}) {--stop} [servername]
|
$(basename ${0}) config
|
||||||
$(basename ${0}) {--restart} [servername] [port] (ip)
|
|
||||||
$(basename ${0}) {--attach} [servername]
|
|
||||||
$(basename ${0}) {--reset} [servername]
|
|
||||||
$(basename ${0}) {--delete} [servername]
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,15 +47,17 @@ while true; do
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
-h|--help)
|
-h|--help)
|
||||||
usage
|
usage
|
||||||
exit 0
|
break
|
||||||
;;
|
;;
|
||||||
-V|--version)
|
-V|--version)
|
||||||
version
|
version
|
||||||
exit 0
|
break
|
||||||
;;
|
;;
|
||||||
-v|--verbose)
|
-v|--verbose)
|
||||||
debuglevel=4
|
debuglevel=4
|
||||||
break
|
;;
|
||||||
|
-n|--dryrun)
|
||||||
|
dryrun=1
|
||||||
;;
|
;;
|
||||||
config)
|
config)
|
||||||
parent="$1"
|
parent="$1"
|
||||||
|
@ -80,3 +79,4 @@ while true; do
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue