Ansible Tower0.8.1Minimum Jenkins requirement: 2.0ID: ansible-tower
This plugin connects Jenkins to Ansible Tower, allowing you to execute job templates.
After installing the plugin you can configure Ansible Tower servers in the Jenkins Global Configuration under the section Ansible Tower by clicking the add button.
The fields are as follows:
|Name||The name that this Ansible Tower installation will be referenced as.|
|URL||The base URL of the Ansible Tower server.|
|Credentials||The credentials within Jenkins to be used to connect to the Ansible Tower server. These should be "Username with password" type credentials.|
|Force Trust Cert||
If your Ansible Tower instance is using an https cert that Jenkins does not trust, and you want the plugin to trust the cert anyway, you can click this box.
You should really understand the implications if you are going to use this option. Its meant for testing purposes only.
This will allow the plugin to write detailed messages into the jenkins.log for debugging purposes. It will show show requests to the server and payloads. This can contain a lot of data. All messages are prefixed with \[Ansible-Tower\].
[Ansible-Tower] building request to https://192.168.56.101/api/v1/workflow_jobs/200/workflow_nodes/
Once the settings are completed, you can test the connection between Jenkins and Ansible Tower by clicking on the Test Connection button.
Adding a Build Step
In a freestyle project a new build step called Ansible Tower is now available:
|Tower Server||The predefined Ansible Tower server to run the template on.|
|Job Template||The name or numerical ID of the job template to be run on the Ansible Tower server.|
Additional variables to be passed to the job. I.e.:
|Job Tags||Any job tags to be passed to Ansible Tower.|
|Limit||The servers to limit the invocation to.|
|Inventory||The name or numeric ID of the inventory to run the job on.|
|Credential||The name or numeric ID of the credentials to run the job with.|
|Verbose||Add additional messages to the Jenkins console about the job run.|
|Import Tower Output||Pull all of the logs from Ansible Tower into the Jenkins console.|
|Remove Color||When importing the Ansible Tower output, strip off the ansi color codings.|
Tower jobs can be executed from workflow scripts.
The towerServer and jobTemplate are the only required parameters.
Expanding Env Vars
You need to install another plugin like [AnsiColor plugin](https://wiki.jenkins-ci.org/display/JENKINS/AnsiColor+Plugin) to output a colorized Ansible log.
If you do not have a plugin like AnsiColor or want to remove the color from the log set removeColor: true.
The plugin supports sending data back to Jenkins as environment variables via the EnvInject plugin. First be sure the plugin is installed (its not a dependency for this plugin, it needs to be installed separately).
If you try to export a variable but don't have the EnvInject plugin installed the Tower plugin will let you know with a message like:
Found environment variables to inject but the EnvInject plugin was not found
There are two method for exporting data: Purpose Driven Logging and Setting Stats
Purpose Driven Logging
Then, in your Tower job simply include a debugging statement like:
- name: Set a Jenkins variable
msg: "JENKINS_EXPORT VAR_NAME=value"
The Tower plugin will recognize this message and use EnvInject plugin to add an environment variable named VAR_NAME with a value of "value" into the pipeline for consumption by downstream tasks.
Another option is to use the set_stats module in Ansible like:
- name: Set a jenkins variable for with stat
- some_name: var_value
- some_other_var : Another value
The Tower plugin will look for variables under JENKINS_EXPORT and use EnvInject plugin to add an environment variables into the pipeline for consumption by downstream tasks. In the previous example two variables would be created: some_name, set to var_value; and some_other_var set to "Another value".
Please reference set_stats documentation for usage and additional parameters, per_host and aggregate are not necessarily needed.
Version 0.8.1 (Mar-10-2018)
- The connection will now be attempted by an authtoken first, if that fails (like on the new versions of AWX) it will revert to Basic Auth. [ JENKINS-50031 ]
Version 0.8.0 (Feb-18-2018)
- Mostly changes when interacting with Tower:
- Added filtered lookups of items by name to reduce time searching through the results and also prevent pagination issues.
- Plugin now utilizes authtokens after initial login. This should decrease run times when the Tower instance is using an external authenticator (such as LDAP).
- Changes to the logging to try and prevent pagination issues and also enhance the speed of looking up logs.
- Contributed code enhancements:
- Source code spelling fixes. (Josh Soref)
- Fixes for warning if passing items (such as credentials) but the job template is not prompting for the item. (Josh Offutt)
- Final check for log entries after the job completes running. (James McShane)
Version 0.7.0 (Jan-02-2018)
- Fixed an issue with purpose driven logging where ending color codes could have been included in variable values
- Added debugging option to Tower configuration
- Added set_stats variable detection for variable export
Version 0.6.1 (Dec-20-2017)
- Bug fixes for last release (it basically didn't work)
- Added some checking for passed credentials and inventory (even if an ID is passed)
- Also tries to give a better error if extra vars are bad
Version 0.6.0 (Dec-12-2017)
- Allowed returning variables back to Jenkins via logging
Version 0.5.4 (Dec-7-2017)
Version 0.5.3 (Dec-2-2017)
- Fixed bug where existing jobs would get NullPointerExceptions when installing the new version of the plugin.
Version 0.5.2 (Dec-2-2017)
- Added option to specify workflow or job templates
Thanks again to Alvin Wong for the suggestion.
Version 0.5.1 (Nov-21-2017)
- Expanded Jenkins EnvVars in all fields being passed to Tower
Thanks to Alvin Wong for the suggestion.
Version 0.5.0 (Nov-11-2017)
- Initial release