Compare commits
No commits in common. "7260396df6acfae86fb5155fd608129c3522681d" and "90d27a5eb6971778f37ae836016d03f46a45b959" have entirely different histories.
7260396df6
...
90d27a5eb6
4 changed files with 135 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
ansible-playbooks/
|
0
config.json
Normal file
0
config.json
Normal file
52
functions/configmgmt
Normal file
52
functions/configmgmt
Normal file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#readonly CONFIG_ROOT="/srv/ansible/playbooks"
|
||||
readonly CONFIG_ROOT="$PWD/ansible-playbooks"
|
||||
|
||||
function 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: $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"
|
||||
}
|
82
novos
Executable file
82
novos
Executable file
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# CONSTANTS
|
||||
readonly PKGVER="0.0.1"
|
||||
readonly LICENSE="GNU AGPLv3"
|
||||
readonly ROOTPATH="$(dirname $(readlink -f $(which ${0})))"
|
||||
#readonly CONFIG="/usr/local/noveria/etc/novos/novos.json
|
||||
readonly CONFIG="./config.json"
|
||||
|
||||
for util in ${ROOTPATH}/functions/*; do
|
||||
source ${util}
|
||||
done
|
||||
|
||||
# VARIABLES
|
||||
declare debuglevel=3
|
||||
declare dryrun=0
|
||||
|
||||
function usage() {
|
||||
cat << EOF
|
||||
usage: $(basename ${0}) <operation> [command] ...
|
||||
operations:
|
||||
$(basename ${0}) {-h --help}
|
||||
$(basename ${0}) {-V --version}
|
||||
$(basename ${0}) {-v --verbose}
|
||||
$(basename ${0}) {-n --dryrun}
|
||||
|
||||
commands:
|
||||
$(basename ${0}) config
|
||||
EOF
|
||||
}
|
||||
|
||||
function version() {
|
||||
cat << EOF
|
||||
Novos v${PKGVER}
|
||||
Copyright (C) 2024 Noveria Network
|
||||
|
||||
This program may be freely redistributed under
|
||||
the terms of the ${LICENSE}
|
||||
EOF
|
||||
}
|
||||
|
||||
###
|
||||
## SCRIPT START
|
||||
###
|
||||
|
||||
while true; do
|
||||
case "${1}" in
|
||||
-h|--help)
|
||||
usage
|
||||
break
|
||||
;;
|
||||
-V|--version)
|
||||
version
|
||||
break
|
||||
;;
|
||||
-v|--verbose)
|
||||
debuglevel=4
|
||||
;;
|
||||
-n|--dryrun)
|
||||
dryrun=1
|
||||
;;
|
||||
config)
|
||||
parent="$1"
|
||||
cmd="$2"
|
||||
shift; shift
|
||||
|
||||
type ${parent}_${cmd} &> /dev/null
|
||||
if [[ $? -eq 0 ]]; then
|
||||
${parent}_${cmd} $@
|
||||
exit 0
|
||||
fi
|
||||
${parent}_help
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo "Invalid argument. Type $(basename $0) -h for help!"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
exit 0
|
Loading…
Reference in a new issue