forked from CCCHH/ansible-infra
Vendor Galaxy Roles and Collections
This commit is contained in:
parent
c1e1897cda
commit
2aed20393f
3553 changed files with 387444 additions and 2 deletions
123
ansible_collections/grafana/grafana/tools/includes/logging.sh
Executable file
123
ansible_collections/grafana/grafana/tools/includes/logging.sh
Executable file
|
|
@ -0,0 +1,123 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
LOG_LEVEL=${LOG_LEVEL:=6} # 7 = debug -> 0 = emergency
|
||||
NO_COLOR="${NO_COLOR:-}"
|
||||
# shellcheck disable=SC2034
|
||||
TRACE="0"
|
||||
|
||||
# _log
|
||||
# -----------------------------------
|
||||
# Handles all logging, all log messages are output to stderr so stdout can still be piped
|
||||
# Example: _log "info" "Some message"
|
||||
# -----------------------------------
|
||||
# shellcheck disable=SC2034
|
||||
_log () {
|
||||
local log_level="${1}" # first option is the level, the rest is the message
|
||||
shift
|
||||
local color_success="\\x1b[32m"
|
||||
local color_debug="\\x1b[36m"
|
||||
local color_info="\\x1b[90m"
|
||||
local color_notice="\\x1b[34m"
|
||||
local color_warning="\\x1b[33m"
|
||||
local color_error="\\x1b[31m"
|
||||
local color_critical="\\x1b[1;31m"
|
||||
local color_alert="\\x1b[1;33;41m"
|
||||
local color_emergency="\\x1b[1;4;5;33;41m"
|
||||
local colorvar="color_${log_level}"
|
||||
local color="${!colorvar:-${color_error}}"
|
||||
local color_reset="\\x1b[0m"
|
||||
|
||||
# If no color is set or a non-recognized terminal is used don't use colors
|
||||
if [[ "${NO_COLOR:-}" = "true" ]] || { [[ "${TERM:-}" != "xterm"* ]] && [[ "${TERM:-}" != "screen"* ]]; } || [[ ! -t 2 ]]; then
|
||||
if [[ "${NO_COLOR:-}" != "false" ]]; then
|
||||
color="";
|
||||
color_reset="";
|
||||
fi
|
||||
fi
|
||||
|
||||
# all remaining arguments are to be printed
|
||||
local log_line=""
|
||||
|
||||
while IFS=$'\n' read -r log_line; do
|
||||
echo -e "$(date +"%Y-%m-%d %H:%M:%S %Z") ${color}[${log_level}]${color_reset} ${log_line}" 1>&2
|
||||
done <<< "${@:-}"
|
||||
}
|
||||
|
||||
# emergency
|
||||
# -----------------------------------
|
||||
# Handles emergency logging
|
||||
# -----------------------------------
|
||||
emergency() {
|
||||
_log emergency "${@}"; exit 1;
|
||||
}
|
||||
|
||||
# success
|
||||
# -----------------------------------
|
||||
# Handles success logging
|
||||
# -----------------------------------
|
||||
success() {
|
||||
_log success "${@}"; true;
|
||||
}
|
||||
|
||||
# alert
|
||||
# -----------------------------------
|
||||
# Handles alert logging
|
||||
# -----------------------------------
|
||||
alert() {
|
||||
[[ "${LOG_LEVEL:-0}" -ge 1 ]] && _log alert "${@}";
|
||||
true;
|
||||
}
|
||||
|
||||
# critical
|
||||
# -----------------------------------
|
||||
# Handles critical logging
|
||||
# -----------------------------------
|
||||
critical() {
|
||||
[[ "${LOG_LEVEL:-0}" -ge 2 ]] && _log critical "${@}";
|
||||
true;
|
||||
}
|
||||
|
||||
# error
|
||||
# -----------------------------------
|
||||
# Handles error logging
|
||||
# -----------------------------------
|
||||
error() {
|
||||
[[ "${LOG_LEVEL:-0}" -ge 3 ]] && _log error "${@}";
|
||||
true;
|
||||
}
|
||||
|
||||
# warning
|
||||
# -----------------------------------
|
||||
# Handles warning logging
|
||||
# -----------------------------------
|
||||
warning() {
|
||||
[[ "${LOG_LEVEL:-0}" -ge 4 ]] && _log warning "${@}";
|
||||
true;
|
||||
}
|
||||
|
||||
# notice
|
||||
# -----------------------------------
|
||||
# Handles notice logging
|
||||
# -----------------------------------
|
||||
notice() {
|
||||
[[ "${LOG_LEVEL:-0}" -ge 5 ]] && _log notice "${@}";
|
||||
true;
|
||||
}
|
||||
|
||||
# info
|
||||
# -----------------------------------
|
||||
# Handles info logging
|
||||
# -----------------------------------
|
||||
info() {
|
||||
[[ "${LOG_LEVEL:-0}" -ge 6 ]] && _log info "${@}";
|
||||
true;
|
||||
}
|
||||
|
||||
# debug
|
||||
# -----------------------------------
|
||||
# Handles debug logging and prepends the name of the that called debug in front of the message
|
||||
# -----------------------------------
|
||||
debug() {
|
||||
[[ "${LOG_LEVEL:-0}" -ge 7 ]] && _log debug "${FUNCNAME[1]}() ${*}";
|
||||
true;
|
||||
}
|
||||
66
ansible_collections/grafana/grafana/tools/includes/utils.sh
Executable file
66
ansible_collections/grafana/grafana/tools/includes/utils.sh
Executable file
|
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# heading
|
||||
# -----------------------------------
|
||||
# Print standard heading
|
||||
# -----------------------------------
|
||||
heading() {
|
||||
local title="${1}"
|
||||
local message="${2}"
|
||||
local width="75"
|
||||
local orange="\\033[38;5;202m"
|
||||
local reset="\\033[0m"
|
||||
local bold="\\x1b[1m"
|
||||
echo ""
|
||||
echo -e "${orange} ▒▒▓▓▒▒▒▓ ${reset} ____ __ _ _ "
|
||||
echo -e "${orange} ▓▓▓ ▒ ${reset} / ___| _ __ __ _ / _| __ _ _ __ __ _ | | __ _ | |__ ___ "
|
||||
echo -e "${orange} ▒▓ ▒▒▒▒▓ ${reset} | | _ | '__| / _ || |_ / _ || '_ \\ / _ | | | / _ || '_ \\ / __|"
|
||||
echo -e "${orange} ▒▓▓ ▒ ▒▒ ${reset} | |_| || | | (_| || _|| (_| || | | || (_| | | |___ | (_| || |_) | \\__\\"
|
||||
echo -e "${orange} ▒▓▒ ▒▓ ${reset} \\____||_| \\__,_||_| \\__,_||_| |_| \\__,_| |_____| \\__,_||_.__/ |___/"
|
||||
echo -e "${orange} ▒▒▒ ▒▒▒ ${reset} "
|
||||
echo -e "${orange} ▒▒▒▒▒ ${reset} $(repeat $(( ((width - ${#title}) - 2) / 2)) " ")${bold}$title${reset}"
|
||||
echo -e "${reset} $(repeat $(( ((width - ${#message}) - 2) / 2)) " ")$message${reset}"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# repeat
|
||||
# -----------------------------------
|
||||
# Repeat a Character N number of times
|
||||
# -----------------------------------
|
||||
repeat(){
|
||||
local times="${1:-80}"
|
||||
local character="${2:-=}"
|
||||
local start=1
|
||||
local range
|
||||
range=$(seq "$start" "$times")
|
||||
local str=""
|
||||
# shellcheck disable=SC2034
|
||||
for i in $range; do
|
||||
str="$str${character}"
|
||||
done
|
||||
echo "$str"
|
||||
}
|
||||
|
||||
# lintWarning
|
||||
# -----------------------------------
|
||||
# Output a Lint Warning Message
|
||||
# -----------------------------------
|
||||
lintWarning() {
|
||||
local msg="${1}"
|
||||
local color_warning="\\x1b[33m"
|
||||
local color_reset="\\x1b[0m"
|
||||
local bold="\\x1b[1m"
|
||||
echo -e " ‣ ${color_warning}${bold}[warn]${color_reset} $msg"
|
||||
}
|
||||
|
||||
# lintError
|
||||
# -----------------------------------
|
||||
# Output a Lint Error Message
|
||||
# -----------------------------------
|
||||
lintError() {
|
||||
local msg="${1}"
|
||||
local color_error="\\x1b[31m"
|
||||
local color_reset="\\x1b[0m"
|
||||
local bold="\\x1b[1m"
|
||||
echo -e " ‣ ${color_error}${bold}[error]${color_reset} $msg"
|
||||
}
|
||||
39
ansible_collections/grafana/grafana/tools/lint-ansible.sh
Executable file
39
ansible_collections/grafana/grafana/tools/lint-ansible.sh
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "$(pwd)/tools/includes/utils.sh"
|
||||
|
||||
source "./tools/includes/logging.sh"
|
||||
|
||||
# output the heading
|
||||
heading "Grafana Ansible Collection" "Performing Ansible Linting using ansible-lint"
|
||||
|
||||
# make sure pipenv exists
|
||||
if [[ "$(command -v pipenv)" = "" ]]; then
|
||||
echo >&2 "pipenv command is required, see (https://pipenv.pypa.io/en/latest/) or run: brew install pipenv";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# make sure yamllint exists
|
||||
if [[ "$(pipenv run pip freeze | grep -c "ansible-lint")" == "0" ]]; then
|
||||
echo >&2 "ansible-lint command is required, see (https://pypi.org/project/ansible-lint/). Run \"make install\" to install it.";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# determine whether or not the script is called directly or sourced
|
||||
(return 0 2>/dev/null) && sourced=1 || sourced=0
|
||||
|
||||
# run yamllint
|
||||
echo "$(pwd)/.ansible-lint"
|
||||
pipenv run ansible-lint --config-file "$(pwd)/.ansible-lint" --strict
|
||||
statusCode="$?"
|
||||
|
||||
if [[ "$statusCode" == "0" ]]; then
|
||||
echo "no issues found"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo ""
|
||||
# if the script was called by another, send a valid exit code
|
||||
if [[ "$sourced" == "1" ]]; then
|
||||
return "$statusCode"
|
||||
fi
|
||||
38
ansible_collections/grafana/grafana/tools/lint-editorconfig.sh
Executable file
38
ansible_collections/grafana/grafana/tools/lint-editorconfig.sh
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "$(pwd)/tools/includes/utils.sh"
|
||||
|
||||
source "./tools/includes/logging.sh"
|
||||
|
||||
# output the heading
|
||||
heading "Grafana Ansible Collection" "Performing Editorconfig Linting using editorconfig-checker"
|
||||
|
||||
# check to see if remark is installed
|
||||
if [[ ! -f "$(pwd)"/node_modules/.bin/editorconfig-checker ]]; then
|
||||
emergency "editorconfig-checker node module is not installed, please run: make install";
|
||||
fi
|
||||
|
||||
# determine whether or not the script is called directly or sourced
|
||||
(return 0 2>/dev/null) && sourced=1 || sourced=0
|
||||
|
||||
statusCode=0
|
||||
./node_modules/.bin/editorconfig-checker -config="$(pwd)/.editorconfig" -exclude "LICENSE|.+\.txt|.+\.py"
|
||||
currentCode="$?"
|
||||
# only override the statusCode if it is 0
|
||||
if [[ "$statusCode" == 0 ]]; then
|
||||
statusCode="$currentCode"
|
||||
fi
|
||||
|
||||
if [[ "$statusCode" == "0" ]]; then
|
||||
echo "no issues found"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# if the script was called by another, send a valid exit code
|
||||
if [[ "$sourced" == "1" ]]; then
|
||||
return "$statusCode"
|
||||
else
|
||||
exit "$statusCode"
|
||||
fi
|
||||
49
ansible_collections/grafana/grafana/tools/lint-markdown.sh
Executable file
49
ansible_collections/grafana/grafana/tools/lint-markdown.sh
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "$(pwd)/tools/includes/utils.sh"
|
||||
|
||||
source "./tools/includes/logging.sh"
|
||||
|
||||
# output the heading
|
||||
heading "Grafana Ansible Collection" "Performing Markdown Linting using markdownlint"
|
||||
|
||||
# check to see if remark is installed
|
||||
if [[ ! -f "$(pwd)"/node_modules/.bin/markdownlint-cli2 ]]; then
|
||||
emergency "markdownlint-cli2 node module is not installed, please run: make install";
|
||||
fi
|
||||
|
||||
# determine whether or not the script is called directly or sourced
|
||||
(return 0 2>/dev/null) && sourced=1 || sourced=0
|
||||
|
||||
statusCode=0
|
||||
while read -r dir; do
|
||||
info "Checking file/directory: $dir"
|
||||
./node_modules/.bin/markdownlint-cli2-config "$(pwd)/.markdownlint.yaml" "$dir"
|
||||
currentCode="$?"
|
||||
# if the current code is 0, output the file name for logging purposes
|
||||
if [[ "$currentCode" == 0 ]]; then
|
||||
echo -e "\\x1b[32m$dir\\x1b[0m: no issues found"
|
||||
fi
|
||||
# only override the statusCode if it is 0
|
||||
if [[ "$statusCode" == 0 ]]; then
|
||||
statusCode="$currentCode"
|
||||
fi
|
||||
echo ""
|
||||
done < <(find . -type f -name "*.md" -not -path "./node_modules/*" -not -path "./.git/*" -print0 | \
|
||||
xargs -0 dirname | \
|
||||
sort -nr | \
|
||||
uniq | \
|
||||
sort | \
|
||||
xargs printf -- '%s/*.md\n' | \
|
||||
sed 's|\./\*\.md|./README.md|'
|
||||
)
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# if the script was called by another, send a valid exit code
|
||||
if [[ "$sourced" == "1" ]]; then
|
||||
return "$statusCode"
|
||||
else
|
||||
exit "$statusCode"
|
||||
fi
|
||||
46
ansible_collections/grafana/grafana/tools/lint-shell.sh
Executable file
46
ansible_collections/grafana/grafana/tools/lint-shell.sh
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "$(pwd)/tools/includes/utils.sh"
|
||||
|
||||
source "./tools/includes/logging.sh"
|
||||
|
||||
# output the heading
|
||||
heading "Grafana Ansible Collection" "Performing Shell Linting using shellcheck"
|
||||
|
||||
# check to see if shellcheck is installed
|
||||
if [[ "$(command -v shellcheck)" = "" ]]; then
|
||||
emergency "shellcheck is required if running lint locally, see: (https://shellcheck.net) or run: brew install nvm && nvm install 18";
|
||||
fi
|
||||
|
||||
# determine whether or not the script is called directly or sourced
|
||||
(return 0 2>/dev/null) && sourced=1 || sourced=0
|
||||
|
||||
statusCode=0
|
||||
while read -r file; do
|
||||
shellcheck \
|
||||
--external-sources \
|
||||
--shell bash \
|
||||
--source-path "$(dirname "$file")" \
|
||||
"$file"
|
||||
currentCode="$?"
|
||||
# if the current code is 0, output the file name for logging purposes
|
||||
if [[ "$currentCode" == 0 ]]; then
|
||||
echo -e "\\x1b[32m$file\\x1b[0m: no issues found"
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
# only override the statusCode if it is 0
|
||||
if [[ "$statusCode" == 0 ]]; then
|
||||
statusCode="$currentCode"
|
||||
fi
|
||||
done < <(find . -type f -name "*.sh" -not -path "./node_modules/*" -not -path "./.git/*")
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# if the script was called by another, send a valid exit code
|
||||
if [[ "$sourced" == "1" ]]; then
|
||||
return "$statusCode"
|
||||
else
|
||||
exit "$statusCode"
|
||||
fi
|
||||
40
ansible_collections/grafana/grafana/tools/lint-text.sh
Executable file
40
ansible_collections/grafana/grafana/tools/lint-text.sh
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "$(pwd)/tools/includes/utils.sh"
|
||||
|
||||
source "./tools/includes/logging.sh"
|
||||
|
||||
# output the heading
|
||||
heading "Grafana Ansible Collections" "Performing Text Linting using textlint"
|
||||
|
||||
# check to see if remark is installed
|
||||
if [[ ! -f "$(pwd)"/node_modules/.bin/textlint ]]; then
|
||||
emergency "remark node module is not installed, please run: make install";
|
||||
fi
|
||||
|
||||
# determine whether or not the script is called directly or sourced
|
||||
(return 0 2>/dev/null) && sourced=1 || sourced=0
|
||||
|
||||
statusCode=0
|
||||
while read -r file; do
|
||||
"$(pwd)"/node_modules/.bin/textlint --config "$(pwd)/.textlintrc" "$file"
|
||||
currentCode="$?"
|
||||
# if the current code is 0, output the file name for logging purposes
|
||||
if [[ "$currentCode" == 0 ]]; then
|
||||
echo -e "\\x1b[32m$file\\x1b[0m: no issues found"
|
||||
fi
|
||||
# only override the statusCode if it is 0
|
||||
if [[ "$statusCode" == 0 ]]; then
|
||||
statusCode="$currentCode"
|
||||
fi
|
||||
done < <(find . -type f -name "*.md" -not -path "./node_modules/*" -not -path "./.git/*")
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# if the script was called by another, send a valid exit code
|
||||
if [[ "$sourced" == "1" ]]; then
|
||||
return "$statusCode"
|
||||
else
|
||||
exit "$statusCode"
|
||||
fi
|
||||
37
ansible_collections/grafana/grafana/tools/lint-yaml.sh
Executable file
37
ansible_collections/grafana/grafana/tools/lint-yaml.sh
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "$(pwd)/tools/includes/utils.sh"
|
||||
|
||||
source "./tools/includes/logging.sh"
|
||||
|
||||
# output the heading
|
||||
heading "Grafana Ansible Collection" "Performing YAML Linting using yamllint"
|
||||
|
||||
# make sure pipenv exists
|
||||
if [[ "$(command -v pipenv)" = "" ]]; then
|
||||
echo >&2 "pipenv command is required, see (https://pipenv.pypa.io/en/latest/) or run: brew install pipenv";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# make sure yamllint exists
|
||||
if [[ "$(pipenv run pip freeze | grep -c "yamllint")" == "0" ]]; then
|
||||
echo >&2 "yamllint command is required, see (https://pypi.org/project/yamllint/). Run \"make install\" to install it.";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# determine whether or not the script is called directly or sourced
|
||||
(return 0 2>/dev/null) && sourced=1 || sourced=0
|
||||
|
||||
# run yamllint
|
||||
pipenv run yamllint --strict --config-file "$(pwd)/.yamllint" .
|
||||
statusCode="$?"
|
||||
|
||||
if [[ "$statusCode" == "0" ]]; then
|
||||
echo "no issues found"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# if the script was called by another, send a valid exit code
|
||||
if [[ "$sourced" == "1" ]]; then
|
||||
return "$statusCode"
|
||||
fi
|
||||
39
ansible_collections/grafana/grafana/tools/setup.sh
Executable file
39
ansible_collections/grafana/grafana/tools/setup.sh
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source "$(pwd)/tools/includes/utils.sh"
|
||||
|
||||
source "./tools/includes/logging.sh"
|
||||
|
||||
# output the heading
|
||||
heading "Grafana Ansible Collection" "Performing Setup Checks"
|
||||
|
||||
# make sure Node exists
|
||||
info "Checking to see if Node is installed"
|
||||
if [[ "$(command -v node)" = "" ]]; then
|
||||
warning "node is required if running lint locally, see: (https://nodejs.org) or run: brew install nvm && nvm install 18";
|
||||
else
|
||||
success "node is installed"
|
||||
fi
|
||||
|
||||
# make sure yarn exists
|
||||
info "Checking to see if yarn is installed"
|
||||
if [[ "$(command -v yarn)" = "" ]]; then
|
||||
warning "yarn is required if running lint locally, see: (https://yarnpkg.com) or run: brew install yarn";
|
||||
else
|
||||
success "yarn is installed"
|
||||
fi
|
||||
|
||||
# make sure shellcheck exists
|
||||
info "Checking to see if shellcheck is installed"
|
||||
if [[ "$(command -v shellcheck)" = "" ]]; then
|
||||
warning "shellcheck is required if running lint locally, see: (https://shellcheck.net) or run: brew install nvm && nvm install 18";
|
||||
else
|
||||
success "shellcheck is installed"
|
||||
fi
|
||||
|
||||
# make sure pipenv exists
|
||||
if [[ "$(command -v pipenv)" = "" ]]; then
|
||||
warning "pipenv command is required, see (https://pipenv.pypa.io/en/latest/) or run: brew install pipenv";
|
||||
else
|
||||
success "pipenv is installed"
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue