Integration Hub - Ansible Job Template Issues

Brady Holliday
Tera Guru

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:

find_real_file.png

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!

1 ACCEPTED SOLUTION

Brady Holliday
Tera Guru

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"}}

 

find_real_file.png

 

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.

find_real_file.png

(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);

View solution in original post

2 REPLIES 2

Brady Holliday
Tera Guru

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"}}

 

find_real_file.png

 

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.

find_real_file.png

(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);

Madhura Ambede
Tera Contributor

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

MadhuraAmbede_0-1720193195048.png

Can you please assist here.