- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2022 08:38 AM
We are currently trying to configure a ServiceNow catalog item to pass extra variables into Ansible to kick off a Job Template. When there aren't extra variables involved Ansible can successfully kick off the job however, when we try to pass extra variables the job does not kick off and on ServiceNow's side it looks like it passed "null" as the extra_vars.
Here is an example of what we are trying to pass to Ansible:
Is our code formatted correctly/is there anything special that we need to do to pass extra_vars variables to Ansible from ServiceNow?
Any Help is much Appreciated!
Solved! Go to Solution.
- Labels:
-
Flow Designer
-
IntegrationHub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 01:07 PM
The solution to this issue is to replace the OOB Action "Launch job Template" with the variable that matches the Ansible Job.
The OOB Payload takes the Extra Arguments you inserted into the action (e.g. {"ansible_variable1": "ansible_value1", "ansible_variable2":"ansible_value2"} ) and adds data to the first part of it (process shown in the picture below)
This results in the payload that is sent to look like this {"data":{"ansible_variable1": "ansible_value1", "ansible_variable2":"ansible_value2"}}
Changing the OOB action to use the same variable that is used within the Ansible Job Template (instead of the data variable listed above in the photo) fixes the null issue. Thus the end result should look something like this.
(function execute(inputs, outputs) {
var payload = {};
inputs = new AnsibleUtils().trimStringInputs(inputs);
outputs.job_template_id = inputs.job_template_id;
if (inputs.extra_vars) {
payload.extra_vars = new AnsibleUtils().validateJson(inputs.extra_vars);
}
outputs.payload = JSON.stringify(payload);
})(inputs, outputs);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 01:07 PM
The solution to this issue is to replace the OOB Action "Launch job Template" with the variable that matches the Ansible Job.
The OOB Payload takes the Extra Arguments you inserted into the action (e.g. {"ansible_variable1": "ansible_value1", "ansible_variable2":"ansible_value2"} ) and adds data to the first part of it (process shown in the picture below)
This results in the payload that is sent to look like this {"data":{"ansible_variable1": "ansible_value1", "ansible_variable2":"ansible_value2"}}
Changing the OOB action to use the same variable that is used within the Ansible Job Template (instead of the data variable listed above in the photo) fixes the null issue. Thus the end result should look something like this.
(function execute(inputs, outputs) {
var payload = {};
inputs = new AnsibleUtils().trimStringInputs(inputs);
outputs.job_template_id = inputs.job_template_id;
if (inputs.extra_vars) {
payload.extra_vars = new AnsibleUtils().validateJson(inputs.extra_vars);
}
outputs.payload = JSON.stringify(payload);
})(inputs, outputs);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 08:32 AM
Hello @Brady Holliday
Your previous solution was helpful,
Now I am getting stuck to get the job details and I am getting an error. I want to display the data in servicenow sc_task
Can you please assist here.