@eu4ia/node-red-contrib-awx
Version:
Node to launch playbooks in awx
167 lines (138 loc) • 6.5 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('awx-launch',{
category: 'eu4ia',
color: '#ee0000',
defaults: {
name: {value:""},
awxService: {type: "awx-config", required: true},
jobTemplate: {
value: "",
validate: RED.validators.typedInput('jobTemplateType')
},
jobTemplateType: {value: "str"},
proxy: {type:"http proxy",required: false},
advanced: {value: false},
initialWait: {value: 10},
interval: {value: 5},
timeout: {value: 5}
},
inputs:1,
outputs:2,
icon: "ansible_A.png",
label: function() {
return this.name || "awx-launch";
},
outputLabels: ["success", "error"],
oneditprepare: function() {
// typedInput
$("#node-input-jobTemplate").typedInput({
default: "str",
value: "",
typeField: $("#node-input-jobTemplateType"),
types: [ 'num', 'str', 'msg', 'flow', 'global']
})
// Proxy Settings
function updateProxyOptions() {
if ($("#node-input-useProxy").is(":checked")) {
$("#form-row-proxy").show();
} else {
$("#form-row-proxy").hide();
}
}
if (this.proxy) {
$("#node-input-useProxy").prop("checked", true);
} else {
$("#node-input-useProxy").prop("checked", false);
}
updateProxyOptions();
$("#node-input-useProxy").on("click", function() {
updateProxyOptions();
});
// Advanced settings
if (this.advanced) {
$('#node-input-advanced').prop('checked', true);
} else {
$('#node-input-advanced').prop('checked', false);
}
function advancedChanged() {
if ($("#node-input-advanced").is(':checked')) {
$(".form-row-advanced").show();
} else {
$(".form-row-advanced").hide();
}
}
$("#node-input-advanced").on("click", advancedChanged);
advancedChanged();
},
oneditsave: function() {
if (!$("#node-input-useProxy").is(":checked")) {
$("#node-input-proxy").val("_ADD_");
}
}
});
</script>
<script type="text/html" data-template-name="awx-launch">
<div class="form-row">
<label for="node-input-awxService"><i class="fa fa-globe"></i> AWX Service</label>
<input type="text" id="node-input-awxService">
</div>
<div class="form-row">
<label for="node-input-jobTemplate"><i class="fa fa-lock"></i> Job Template</label>
<input type="text" id="node-input-jobTemplate" style="width:70%">
<input type="hidden" id="node-input-jobTemplateType">
</div>
<hr>
<div class="form-row">
<input type="checkbox" id="node-input-useProxy" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-useProxy" style="width: auto;">Use Proxy</label>
<div id="form-row-proxy" class="hide">
<label style="width: auto; margin-left: 2em; margin-right: 1em;" for="node-input-proxy"><i class="fa fa-globe"></i> Proxy Config</label><input type="text" style="width: 270px" id="node-input-proxy">
</div>
</div>
<hr>
<div class="form-row">
<input type="checkbox" id="node-input-advanced" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-advanced" style="width: auto"> Advanced Options</label>
</div>
<div class="form-row form-row-advanced">
<label for="node-input-initialWait" style="width: 40%">Initial wait (seconds)</label>
<input type="text" id="node-input-initialWait" style="width:50%">
</div>
<div class="form-row form-row-advanced">
<label for="node-input-interval" style="width: 40%">Polling Interval (seconds)</label>
<input type="text" id="node-input-interval" style="width:50%">
</div>
<div class="form-row form-row-advanced">
<label for="node-input-timeout" style="width: 40%">Timeout (minutes)</label>
<input type="text" id="node-input-timeout" style="width:50%">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/html" data-help-name="awx-launch">
<p>Launch an AWX Job</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt class="optional">payload<span class="property-type">object</span></dt>
<dd>if <code>msg.payload</code> is an object, it will be sent as POST data with the <code>/api/v2/job_templates/{id}/launch/</code> API Call</dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Standard output
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>The response object for AWX API call to <code>/jobs/{jobId}</code> (once the job has finished)</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>The node can be used to launch a new AWX job based on an existing job template. The node launches the job and polls AWX regularly to check the status of the job. The polling intervals can be configured using the <code>advanced options</code> in the the configuration dialog</p>
<p>In the background, the node calls the <code>/api/v2/job_templates/{id}/launch/</code> endpoint on the AWX API. <code>msg.payload</code> is sent along as POST data on this call. Look at the API documentation for more info on what this object should look like</p>
<p>If you send in certain values in the POST data, that will be ignored by the job template (limit, inventory, extra_vars), the job will not be launched to avoid unexpected results</p>
<h3>References</h3>
<ul>
<li><a href="https://docs.ansible.com/ansible-tower/latest/html/towerapi/api_ref.html">AWX API documentation</a></li>
</ul>
</script>