Skip to content

Instantly share code, notes, and snippets.

@chrisgilbert
Last active June 25, 2021 19:17
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save chrisgilbert/58f57c82f74162ed5c0f to your computer and use it in GitHub Desktop.
Save chrisgilbert/58f57c82f74162ed5c0f to your computer and use it in GitHub Desktop.
Run Ansible or Ansible-Playbook from Rundeck
#!/bin/bash
# Interpret whether the input needs to go to ansible, or ansible-playbook and run appropriately
# First update the git repos for each project
/usr/bin/update-git-repos
export ANSIBLE_FORCE_COLOR=1
export ANSIBLE_RETRY_FILES_ENABLED=False
USER=root
echo Command line given was:
echo $0 $@
echo Rundeck project is $RD_JOB_PROJECT
REGEX=".*.yml"
if [[ $2 =~ $REGEX ]]; then
COMMAND=ansible-playbook
ARGS=" $2 -i /etc/ansible/hosts/$RD_JOB_PROJECT -u $3 -vv --limit=$1 $4 $5 $6 $7"
else
COMMAND=ansible
ARGS=" $1 -i /etc/ansible/hosts/$RD_JOB_PROJECT --user=$USER --module-name=$2 --args=\"$3 $4 $5 $6 $7 $8 $9\""
if [ $3 == "rm" ]; then
echo RM commands are disabled.
exit 1
fi
fi
echo Running $COMMAND $ARGS
eval $COMMAND $ARGS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment