Skip to content

Commit

Permalink
add ansible-local.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed Apr 30, 2024
1 parent ea7cfe0 commit c86e63a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions ansible-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# Run Ansible

cd $(dirname $0) && set -e

if [ -f env.sh ]; then
for var in $(cat env.sh); do
if ! echo "$var" | grep "^#" >/dev/null; then
export "$var"
fi
done
fi

# Run playbook
if python3 -m ansible doc -h >/dev/null; then

ansible_eval="python3 -m ansible playbook"

if [ "$ANSIBLE_VAULT" != "" ]; then
echo '#!/bin/bash' > vault-secret
echo "echo $ANSIBLE_VAULT" >> vault-secret
chmod 700 vault-secret
ansible_eval="${ansible_eval} --vault-password-file vault-secret"
fi

if [ -f env.yml ]; then
ansible_eval="${ansible_eval} -e @env.yml"
fi

if [ -d inventory ]; then
ansible_eval="${ansible_eval} -i inventory"
elif [ -f inventory.yaml ]; then
ansible_eval="${ansible_eval} -i inventory.yaml"
fi

ansible_eval="${ansible_eval} -c local -l local ${@}"

set -x
exec $ansible_eval

else
echo "ansible not found. please install."
fi

0 comments on commit c86e63a

Please sign in to comment.