first files for raclette
This commit is contained in:
parent
61b4bcfe8d
commit
8fd6887204
8 changed files with 160 additions and 130 deletions
|
@ -1,3 +1,7 @@
|
||||||
# novos
|
# Raclette
|
||||||
|
|
||||||
A wrapper-script for ansible-playbook
|
A wrapper-script for ansible-playbook with salt-like syntax
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
* raclette-call
|
||||||
|
* raclette-run
|
||||||
|
|
7
functions/call/highstate
Normal file
7
functions/call/highstate
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
readonly CONFIG_ROOT="/srv/ansible/playbooks"
|
||||||
|
|
||||||
|
function state_highstate() {
|
||||||
|
ansible-playbook $([[ $testmode -eq 1 ]] && echo '-C') -D "${CONFIG_ROOT}/top.ansible.yml"
|
||||||
|
}
|
27
functions/call/sls
Normal file
27
functions/call/sls
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#!/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"
|
||||||
|
}
|
|
@ -1,47 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
readonly CONFIG_ROOT="/srv/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() {
|
|
||||||
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') -D "${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') -D "$newpath"
|
|
||||||
}
|
|
7
functions/run/fileserver
Normal file
7
functions/run/fileserver
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
readonly CONFIG_ROOT="/srv/ansible/playbooks"
|
||||||
|
|
||||||
|
function fileserver_update() {
|
||||||
|
git -C "$CONFIG_ROOT" pull
|
||||||
|
}
|
81
novos
81
novos
|
@ -1,81 +0,0 @@
|
||||||
#!/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"
|
|
||||||
|
|
||||||
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
|
|
66
raclette-call
Executable file
66
raclette-call
Executable file
|
@ -0,0 +1,66 @@
|
||||||
|
#!/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/raclette/config.json"
|
||||||
|
|
||||||
|
# VARIABLES
|
||||||
|
declare testmode=0
|
||||||
|
|
||||||
|
function usage() {
|
||||||
|
cat << EOF
|
||||||
|
Usage: $(basename ${0}) [options] <function> [arguments]
|
||||||
|
|
||||||
|
$(basename $0) is used to execute module functions locally on a Raclette Minion
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--version show program's version number and exit
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
function version() {
|
||||||
|
cat << EOF
|
||||||
|
Raclette 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 "$(echo $1 | cut -d. -f1 | cut -d= -f1)" in
|
||||||
|
-h|--help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
--version)
|
||||||
|
version
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
state)
|
||||||
|
command="$(echo $1 | cut -d. -f2)"
|
||||||
|
;;
|
||||||
|
test)
|
||||||
|
if [[ "$(echo $1 | cut -d= -f2)" == "false" ]]; then
|
||||||
|
testmode=0
|
||||||
|
fi
|
||||||
|
testmode=1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid argument. Type $(basename $0) -h for help!"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
source ${ROOTPATH}/functions/call/$command
|
||||||
|
state_${command} $@
|
47
raclette-run
Normal file
47
raclette-run
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
readonly PKGVER="0.0.1"
|
||||||
|
readonly LICENSE="GNU AGPLv3"
|
||||||
|
readonly ROOTPATH="$(dirname $(readlink -f $(which ${0})))"
|
||||||
|
|
||||||
|
function usage() {
|
||||||
|
cat << EOF
|
||||||
|
Usage: $(basename ${0}) [options] <function> [arguments]
|
||||||
|
|
||||||
|
$(basename $0) is the frontend command for executing Raclette Runners. Raclette Runners are
|
||||||
|
modules used to execute convenience functions on the Raclette Master
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--version show program's version number and exit
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
function version() {
|
||||||
|
cat << EOF
|
||||||
|
Raclette 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 "$(echo $1 | cut -d. -f1)" in
|
||||||
|
-h|--help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
fileserver)
|
||||||
|
command="${1/./_/}" # replace dot . with underscore _
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
source ${ROOTPATH}/functions/run/$(echo "$command" | cut -d_ -f1)
|
||||||
|
$command
|
Loading…
Reference in a new issue