diff --git a/cmd.sh b/cmd.sh new file mode 100755 index 0000000..07a5567 --- /dev/null +++ b/cmd.sh @@ -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" diff --git a/play.sh b/play.sh new file mode 100755 index 0000000..989c61d --- /dev/null +++ b/play.sh @@ -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 diff --git a/playbook_template.yml b/playbook_template.yml new file mode 100644 index 0000000..6479fc2 --- /dev/null +++ b/playbook_template.yml @@ -0,0 +1,8 @@ +# vim: ft=yaml.ansible +# code: language=ansible +--- +- name: Run play + hosts: ${TARGET_HOSTS} + remote_user: ansible + become: true + roles: ${ROLES}