Add wrapper scripts to run plays and custom commands

This commit is contained in:
Sam A. 2023-12-23 15:25:57 +01:00
parent c091a4f869
commit cbdc7119fb
Signed by: samsapti
GPG Key ID: CBBBE7371E81C4EA
3 changed files with 40 additions and 0 deletions

7
cmd.sh Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
HOSTS="$1"
CMD="$2"
ansible -u ansible -m shell -a "$CMD" \
--become --ask-become-pass --ask-vault-pass "$HOSTS"

25
play.sh Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
HOSTS="$1"
case $HOSTS in
*app*)
ROLES="['virt-common', 'docker', 'apps']" ;;
*db*)
ROLES="['virt-common', 'postgresql']" ;;
*prx*|proxy*)
ROLES="['virt-common', 'docker', 'proxy']" ;;
*)
ROLES="['virt-common']" ;;
esac
export HOSTS
export ROLES
PLAYBOOK="play-$(tr -dc A-Za-z < /dev/urandom | head -c 10).yml"
envsubst < playbook_template.yml > "$PLAYBOOK"
ansible-playbook "$PLAYBOOK" --ask-become-pass --ask-vault-pass
STATUS=$?
rm -f "$PLAYBOOK"
exit $STATUS

8
playbook_template.yml Normal file
View File

@ -0,0 +1,8 @@
# vim: ft=yaml.ansible
# code: language=ansible
---
- name: Run play
hosts: ${TARGET_HOSTS}
remote_user: ansible
become: true
roles: ${ROLES}