Skip to content

Instantly share code, notes, and snippets.

@baztian
Last active December 1, 2021 14:28
Show Gist options
  • Save baztian/5a7b87ebc223fd6f6fe7cc4cbeb7156e to your computer and use it in GitHub Desktop.
Save baztian/5a7b87ebc223fd6f6fe7cc4cbeb7156e to your computer and use it in GitHub Desktop.
Execute ansible role
#!/bin/sh
set -e
if [ $# -lt 1 ]; then
echo "Executes a ansible role on localhost" > /dev/stderr
echo "Usage $(basename $0) ROLENAME [additional ansible-playbook options]" > /dev/stderr
echo "Example: $(basename $0) baztian.keepass -K -b" > /dev/stderr
exit 1
fi
ROLE=$1
shift
TMPFILE="$(mktemp -t playbook-XXXXXX.yml)"
cat > $TMPFILE <<HERE
---
- hosts: all
roles:
- role: $ROLE
HERE
ansible-playbook "$TMPFILE" -c local -i localhost, "$@"
rm "$TMPFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment