Passing extra_vars via provisioning callback using PowerShell

Hello,

I have a template that needs to be run against Windows hosts that make use the callback URL to initiate the job against them.

This works for that purpose:

Invoke-WebRequest -Method POST -Body @{host_config_key=‘<auth_key>’}

However, I also need to pass extra_vars as a part of the callback. I’ve tried this several ways and I can’t seem to get it right (I assume it’s some kind of syntax or forwarding thing.).

I don’t know if some of the syntax rules outline in the documentation (i.e. escaping spaces) apply to PowerShell or not, but I tried them anyway to no success. Here’s an example of what I’m trying:

$extra_vars = ‘{"instance_id" : "12345"}’

$body = @{}
$body.Add(‘host_config_key’, ‘54321’)
$body.Add(‘extra_vars’, $extra_vars)

$response = Invoke-WebRequest -Method POST -Body $body

This will still launch the template, but when I reference the instance_id var it isn’t defined.

Any help would be greatly appreciated.

Can you share both your code and the results you are getting? I’m strugling a bit to understand.

If you are attempting to use say win_template to create a powershell script then you’ll need to use the {{ }} in your template file so that ansible knows to substitute in the value for the variable name that is inside the {{ }}.

There might be an easier way to do what you want, - you can pass arguments to powershell scripts run via the script module for example

Jon