diff --git a/README.md b/README.md index 0d87ec2..65e032e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ -# novos +# Raclette -A wrapper-script for ansible-playbook \ No newline at end of file +A wrapper-script for ansible-playbook with salt-like syntax + +Commands: +* raclette-call +* raclette-run diff --git a/functions/call/highstate b/functions/call/highstate new file mode 100644 index 0000000..00a0231 --- /dev/null +++ b/functions/call/highstate @@ -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" +} diff --git a/functions/call/sls b/functions/call/sls new file mode 100644 index 0000000..3985b1c --- /dev/null +++ b/functions/call/sls @@ -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" +} diff --git a/functions/configmgmt b/functions/configmgmt deleted file mode 100644 index c29e614..0000000 --- a/functions/configmgmt +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env bash - -readonly CONFIG_ROOT="/srv/ansible/playbooks" - -function config_help() { - cat << EOF -$(basename ${0}) config [...] -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" -} diff --git a/functions/run/fileserver b/functions/run/fileserver new file mode 100644 index 0000000..939135d --- /dev/null +++ b/functions/run/fileserver @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +readonly CONFIG_ROOT="/srv/ansible/playbooks" + +function fileserver_update() { + git -C "$CONFIG_ROOT" pull +} diff --git a/novos b/novos deleted file mode 100755 index 50542ee..0000000 --- a/novos +++ /dev/null @@ -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}) [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 diff --git a/raclette-call b/raclette-call new file mode 100755 index 0000000..929bd48 --- /dev/null +++ b/raclette-call @@ -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] [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} $@ diff --git a/raclette-run b/raclette-run new file mode 100644 index 0000000..c292a9c --- /dev/null +++ b/raclette-run @@ -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] [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