ansible/dev-helpers.sh
2026-08-05 19:19:58 +02:00

101 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# source this file
function get-requirements(){
uv sync --prerelease=if-necessary-or-explicit
for req in roles/**/*/requirements.txt; do
uv pip install --prerelease=allow --requirements $req;
done
for req in roles/**/*/requirements.yml;
do ansible-galaxy install -r $req;
done
ansible-galaxy collection install -r requirements.yaml
ansible-galaxy role install -r requirements.yaml
}
function unlock(){
export BW_SESSION=$(bw unlock --raw) || return 1
echo $BW_SESSION > /tmp/urmel_ansible_bw_session
}
function pull-services(){
local pull_all=false
while getopts "a" opt; do
case $opt in
a)
pull_all=true
;;
*)
;;
esac
done
shift $((OPTIND -1))
local services=()
if [ "$pull_all" = true ]; then
services=($(find roles/))
else
services=($(cat config.ini | grep "services" | cut -d= -f2- | tr ',' ' '))
fi
for service in "${services[@]}"; do
echo "Pulling $service"
git -C roles/$service pull
done
}
function create-role-here(){
mkdir defaults files libary tasks templates meta handlers
rolename=$(pwd | rev | cut -d "/" -f 1 | rev)
echo "# $rolename" > README.md
cat <<EOF> tasks/main.yml
---
- name: "set local variables from overrides and defaults"
set_fact:
${rolename}: "{{ (${rolename}_defaults | combine(${rolename}_override, recursive=True)) if ${rolename}_override else ${rolename}_defaults }}"
EOF
cat <<EOF> defaults/main.yml
path: /srv/{{ role_name }}
${rolename}_override: {}
${rolename}_defaults: {}
EOF
cat <<EOF> meta/main.yml
---
galaxy_info:
author: "Niklas Freese <niklas@urmel.de>"
description: ${rolename}
company: "Urmel Services"
license: AGPL-3.0-or-later
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies:
- role: base
EOF
cat <<EOF> handlers/main.yml
- name: restart container
community.docker.docker_compose_v2:
project_src: "{{ path }}"
project_name: "{{ role_name }}"
recreate: "always"
services: ["${rolename}"]
state: "restarted"
when: not _${rolename}_already_restarted
EOF
}