Files
Ansible-Build/task
T
2021-09-01 20:16:55 +02:00

78 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
function help() {
echo
echo "$1 <command> [options]"
echo
echo "commands:"
echo
column -t -s"|" ./task.md | tail -n +3
echo
}
function generate-passwordfile() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
export VAULTPASSWORD=$1
echo "$VAULTPASSWORD" > .vault_pass
chmod 600 .vault_pass
}
function venv-init() {
python3 -m venv venv
source venv/bin/activate
}
function activate-venv() {
source venv/bin/activate
}
function install-packages() {
activate-venv
sudo apt install graphviz
pip install -r requirements.txt
ansible-galaxy collection install community.general
}
function update-docs() {
activate-venv
python ./library/graph.py
}
function list-hosts() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
activate-venv
ansible -i $1 all --list-hosts
}
case "$1" in
init)
sudo touch /var/log/ansible.log
sudo chown $USER: /var/log/ansible.log
venv-init
;;
generate-passwordfile)
generate-passwordfile $2
;;
install-ansible)
activate-venv
pip install ansible
;;
install-packages)
install-packages
;;
update-docs)
update-docs
;;
list-hosts)
list-hosts $2
;;
lint)
activate-venv
ansible-lint *.yml
;;
*)
help task
exit 1
;;
esac