Skip to content

Instantly share code, notes, and snippets.

@Theaxiom
Forked from chrisgilbert/gist:58f57c82f74162ed5c0f
Last active November 19, 2016 14:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Theaxiom/85fb9c19cd5965c7f9b7 to your computer and use it in GitHub Desktop.
Save Theaxiom/85fb9c19cd5965c7f9b7 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
@Theaxiom
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment