Skip to content

Commit

Permalink
Add extra_vars map, job tags, credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
droberts2013 committed Jun 20, 2023
1 parent 7e41302 commit e35d467
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 66 deletions.
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
*/

plugins {
id "com.github.hierynomus.license" version "0.11.0"
id "com.github.hierynomus.license" version "0.16.1"
}

defaultTasks 'build'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'maven'

version='1.0.0'
version='1.1.1'
sourceSets.main.resources.srcDirs = ["src"]

license {
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Wed May 02 14:39:33 CEST 2018
languageLevel=1.11
xlPluginsPluginVersion=1.3.5
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.11.jdk/Contents/Home
34 changes: 34 additions & 0 deletions gradle/buildViaTravis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# This script will build the project.

SWITCHES="--info --stacktrace"

GRADLE_VERSION=$(./gradlew -version | grep Gradle | cut -d ' ' -f 2)

if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo -e "Build Pull Request #$TRAVIS_PULL_REQUEST => Branch [$TRAVIS_BRANCH]"
./gradlew clean build $SWITCHES
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" == "" ]; then
echo -e 'Build Branch with Snapshot => Branch ['$TRAVIS_BRANCH']'
./gradlew -Prelease.travisci=true clean snapshot $SWITCHES
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
echo -e 'Build Branch for Release => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG']'
case "$TRAVIS_TAG" in
*-rc\.*)
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true clean candidate $SWITCHES
;;
*)
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true clean final $SWITCHES
;;
esac
else
echo -e 'WARN: Should not be here => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG'] Pull Request ['$TRAVIS_PULL_REQUEST']'
./gradlew clean build $SWITCHES
fi

EXIT=$?

rm -f "$HOME/.gradle/caches/modules-2/modules-2.lock"
rm -rf "$HOME/.gradle/caches/$GRADLE_VERSION/plugin-resolution"

exit $EXIT
8 changes: 8 additions & 0 deletions gradle/dependencies.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dependencyManagement {
versions {
docBaseStyleVersion="3.0.3"
xlDeployVersion="9.0.0-alpha.78"
licenseDatabaseVersion="1.2.45"
xlPlatformVersion="2019.2.0-alpha.75"
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
37 changes: 20 additions & 17 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -82,7 +82,6 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -126,11 +125,10 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand All @@ -156,19 +154,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
i=$((i+1))
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -177,9 +175,14 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
27 changes: 19 additions & 8 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem http://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -29,9 +29,6 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

Expand All @@ -40,7 +37,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand All @@ -54,7 +51,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute
if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -64,14 +61,28 @@ echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
Expand Down
51 changes: 30 additions & 21 deletions src/ansibletower/launchAndWait.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
import time
import sys

def create_payload(extra_vars, jobTags, credentials):
body = {}
body['extra_vars'] = extra_vars
body['job_tags'] = ",".join(jobTags)
body['credentials'] = credentials
body_as_string = json.dumps(body)
print "Body returned from create_payload() is %s" % body_as_string
return body_as_string

if not ansibletower:
print("Ansible Tower Server must be provided")
sys.exit(1)
Expand All @@ -40,26 +49,27 @@

if not isWorkflow:
api_url = '/api/v2/job_templates/%s/launch/' % job_template_id
body = { "extra_vars": extra_vars}
response = request.post(api_url,body= json.dumps(body),contentType="application/json",headers=headers)
# body = { "extra_vars": extra_vars}
body_as_string = create_payload(extra_vars, jobTags, credentials)
response = request.post(api_url,body=body_as_string,contentType="application/json",headers=headers)
result = json.loads(response.response)
# Check the response status code to make sure the request was not successful.

if not response.isSuccessful():
print("Failed to run the job template. Server return [%s], with content [%s]" % (response.status, response.response))
sys.exit(1)

job_id= result["id"]

print("```")
print(">>> Job template launched with job id " + str(job_id))
print("```")
print("\n")

num_tries = 0
api_url = '/api/v2/jobs/%s/' % job_id


if max_retries:
while num_tries < int(max_retries):
# Define the URL for the Ansible Tower API endpoint to launch a job.
Expand All @@ -75,12 +85,12 @@
time.sleep(float(wait_interval))
else:
raise Exception("Failed !. Server return [%s], with content [%s]" % (response.status, response.response))

if num_tries == int(max_retries):
# maximum number of tries reached, handle the error
raise Exception("Error: maximum number of tries reached")
else:
# task completed
# task completed
print("```")
print(">>> Task completed after " + str(num_tries) + " tries with status "+ status)
print("```")
Expand All @@ -93,7 +103,7 @@
print("* [>>> Job %s Link](%s/#/jobs/%s) <<<" % (str(job_id), ansibletower['url'], str(job_id)))
print("\n")
result= job_output

else:
while True:
# Define the URL for the Ansible Tower API endpoint to launch a job.
Expand Down Expand Up @@ -122,22 +132,23 @@
result= job_output
else:
api_url = '/api/v2/workflow_job_templates/%s/launch/' % job_template_id
body = { "extra_vars": extra_vars}
response = request.post(api_url,body= json.dumps(body),contentType="application/json",headers=headers)
# body = { "extra_vars": extra_vars}
body_as_string = create_payload(extra_vars, jobTags, credentials)
response = request.post(api_url,body=body_as_string,contentType="application/json",headers=headers)
result = json.loads(response.response)
# Check the response status code to make sure the request was not successful.

if not response.isSuccessful():
print("Failed to run the workflow job template. Server return [%s], with content [%s]" % (response.status, response.response))
sys.exit(1)

job_id= result["id"]

print("```")
print(">>> Workflow job template launched with job id " + str(job_id))
print("```")
print("\n")

num_tries = 0
api_url = '/api/v2/workflow_jobs//%s/' % job_id
if max_retries:
Expand All @@ -155,12 +166,12 @@
time.sleep(float(wait_interval))
else:
raise Exception("Failed !. Server return [%s], with content [%s]" % (response.status, response.response))

if num_tries == int(max_retries):
# maximum number of tries reached, handle the error
raise Exception("Error: maximum number of tries reached")
else:
# task completed
# task completed
print("```")
print(">>> Task completed after " + str(num_tries) + " tries with status "+ status)
print("```")
Expand Down Expand Up @@ -198,9 +209,7 @@
print("\n") # end markdown code block
print("* [>>> Job %s Link](%s/#/jobs/workflow/%s/output) <<<" % (str(job_id), ansibletower['url'], str(job_id)))
print("\n")
result= job_output
result= job_output

if stopOnFailure and not status == 'successful':
raise Exception("Job status is "+ status)


Loading

0 comments on commit e35d467

Please sign in to comment.