Last active
January 18, 2019 03:21
-
-
Save philcryer/fdce90d0b06517a49ff2fdba41b579df to your computer and use it in GitHub Desktop.
tower-job: run an Ansible Tower job via the command-line, and get all the output you would from the Tower console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# tower-job | |
# https://gist.github.com/philcryer/fdce90d0b06517a49ff2fdba41b579df | |
# Variables | |
tower_template_id=574 | |
# Directions | |
# | |
# install tower-cli | |
# sudo pip install tower-cli | |
# | |
# put this file in a root of your project | |
# {{ project_root }}/tower-job | |
# | |
# create a file ~/.tower-cli.cfg with contents: | |
# | |
# [general] | |
# host = fqdn.yourhost.com | |
# username = your-username | |
# password = ssssshhhhhhhh | |
# | |
# add variables from your tower survey to a vars file. we'll use group_vars/tower-job.yml | |
# --- | |
# survey_env: "DEV" | |
# survey_version: "2.0" | |
# survey_mychart_customer: "bob" | |
# | |
# define your job template ID # in variables above | |
# job_template_id=574 | |
# | |
# make this file executable | |
# chmod 755 tower-job | |
# | |
# then run it | |
# ./tower-job | |
set -e | |
if [ ! -d 'group_vars' ]; then | |
echo "No group_vars found, run this out of root of project"; exit 1 | |
fi | |
tower-cli job launch --job-template=$tower_template_id --extra-vars="@group_vars/tower-job.yml" | tee tower-job.pid | |
job_id=$(cat tower-job.pid | tail -n2 | head -n1 | awk '{print $1}') | |
rm tower-job.pid | |
while [ $(tower-cli job list --status=running | grep $job_id | wc -l) -lt '1' ]; do | |
echo -n "-"; sleep 5; | |
done; | |
tower-cli job monitor $job_id | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment