Compare commits
3 commits
main
...
config_con
Author | SHA1 | Date | |
---|---|---|---|
d85cef01c0 | |||
302e43bd92 | |||
ab4a881398 |
8 changed files with 167 additions and 162 deletions
|
@ -1,7 +1,3 @@
|
|||
# Raclette
|
||||
|
||||
A wrapper-script for ansible-playbook with salt-like syntax
|
||||
|
||||
Commands:
|
||||
* raclette-call
|
||||
* raclette-run
|
||||
A wrapper-script for ansible-playbook
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#!/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"
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
#!/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"
|
||||
}
|
85
functions/configmgmt
Normal file
85
functions/configmgmt
Normal file
|
@ -0,0 +1,85 @@
|
|||
#!/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 configure
|
||||
$(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"
|
||||
}
|
||||
|
||||
function config_configure() {
|
||||
# Check if serverspecific.ansible.yml exists, if not: create
|
||||
if [[ ! -f "$CONFIG_ROOT/serverspecific.ansible.yml" ]]; then
|
||||
touch "$CONFIG_ROOT/serverspecific.ansible.yml"
|
||||
fi
|
||||
# Check if 'serverspecific' is inside top.ansible.yml, if not: append
|
||||
if [[ -z $(grep "serverspecific" "$CONFIG_ROOT/top.ansible.yml") ]]; then
|
||||
echo "- import_playbook: serverspecific.ansible.yml" >> "$CONFIG_ROOT/top.ansible.yml"
|
||||
fi
|
||||
|
||||
available_playbooks=($(find "$CONFIG_ROOT" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | grep -vE "^\.[a-z]+"))
|
||||
available_playbooks+=($(find "$CONFIG_ROOT" -mindepth 1 -maxdepth 1 -type f -exec basename {} \; | grep -vE "^\.[a-z]+" | grep -v "top.*" | grep -v "map." | grep -v "serverspecific."))
|
||||
|
||||
top_content=($(cat "$CONFIG_ROOT/top.ansible.yml" | cut -d: -f2 | cut -d/ -f1 | awk '{$1=$1};1'))
|
||||
|
||||
echo "${available_playbooks[@]}"
|
||||
for top_item in ${top_content[@]}; do
|
||||
available_playbooks=( $(echo "${available_playbooks[@]/$top_item}" | awk '{$1=$1};1') )
|
||||
done
|
||||
echo "${available_playbooks[@]}"
|
||||
|
||||
local dialog_string
|
||||
for playbook in "${available_playbooks[@]}"; do
|
||||
[[ $(grep "$playbook" "$CONFIG_ROOT/serverspecific.ansible.yml") ]] && playbook="$playbook:on" || playbook="$playbook:off"
|
||||
echo "$playbook"
|
||||
dialog_string="${dialog_string} $(echo $playbook | cut -d: -f1) .. $(echo $playbook | cut -d: -f2)"
|
||||
done
|
||||
|
||||
selected=($(dialog --output-fd 1 --clear --title "Select additional playbooks to apply" --checklist "available playbooks" 10 70 3 $dialog_string))
|
||||
if [[ -n "${selected[@]}" ]]; then
|
||||
rm -f "$CONFIG_ROOT/serverspecific.ansible.yml"
|
||||
for sel in "${selected[@]}"; do
|
||||
echo "- import_playbook: $sel/init.ansible.yml" >> "$CONFIG_ROOT/serverspecific.ansible.yml"
|
||||
done
|
||||
fi
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
readonly CONFIG_ROOT="/srv/ansible/playbooks"
|
||||
|
||||
function fileserver_update() {
|
||||
git -C "$CONFIG_ROOT" pull
|
||||
}
|
81
raclette
Executable file
81
raclette
Executable file
|
@ -0,0 +1,81 @@
|
|||
#!/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"
|
||||
|
||||
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
|
||||
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 "${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
|
|
@ -1,67 +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/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 [[ $# -gt 0 ]]; 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
|
||||
else
|
||||
testmode=1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Invalid argument. Type $(basename $0) -h for help!"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
source ${ROOTPATH}/functions/call/$command
|
||||
state_${command} $@
|
49
raclette-run
49
raclette-run
|
@ -1,49 +0,0 @@
|
|||
#!/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 [[ $# -gt 0 ]]; do
|
||||
case "$(echo $1 | cut -d. -f1)" in
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
fileserver)
|
||||
command="${1/./_}" # replace dot . with underscore _
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
source ${ROOTPATH}/functions/run/$(echo "$command" | cut -d_ -f1)
|
||||
$command
|
Loading…
Reference in a new issue