I’m not too sure if this is an issue with how I’m parsing to the PS script… or the PS script accepting the arg in json hence posting here sorry…
I have a var that consists of a list of dictionaries. In my play I have a task that runs a Powershell script and the var is parsed in json as an argument.
Below are relevant snippets…
dns_test:
-
{ zone: ‘test.com’, name: ‘test1’, target: ‘1.2.3.4’, type: ‘ARecord’, state: ‘present’ }
-
{ zone: ‘test.com’, name: ‘test2’, target: ‘5.6.7.8’, type: ‘ARecord’, state: ‘present’ }
-
name: Configure DNS
script: files/dns.ps1 {{ dns_test | quote | to_json }}
I’ve tested that I can output dns_test in json format without issues (also tried with filter to_nice_json).
I’ve also tested the Powershell script - this was importing the json file and then using PS cmdlet convert-fromjson - script works without issues when importing the json file (please note I only want to parse the var in json format).
I’ve become stuck when parsing the var in json format to the PS script as an arg - the script expects the arg.
I get the below error when running the play…
“stderr”: “convert-fromjson : The term ‘convert-fromjson’ is not recognized as the name \r\nof a cmdlet, function, script file, or operable program. Check the spelling of \r\nthe name, or if a path was included, verify that the path is correct and try \r\nagain.\r\nAt C:\Users\ansible\AppData\Local\Temp\ansible-tmp-1550181100.61-21894512685493\r\n9\dns.ps1:27 char:9\r\n+ $json | convert-fromjson\r\n+ ~~~~~~~~~~~~~~~~\r\n + CategoryInfo : ObjectNotFound: (convert-fromjson:String) , Co \r\n mmandNotFoundException\r\n + FullyQualifiedErrorId : CommandNotFoundException\r\n \r\n\r\n”,
63
“stderr_lines”: [
64
"convert-fromjson : The term ‘convert-fromjson’ is not recognized as the name ",
65
"of a cmdlet, function, script file, or operable program. Check the spe…
The line in the PS script for the arg is…
$json = $args[0] | convert-fromjson
I’ve also tried parsing the var without using the filter of “quote”…
script: files/dns.ps1 {{ dns_test | to_json }}
When leaving out the “quote” filter I get a different error…
{
“stderr_lines”: [
“At line:1 char:99”,
“+ … \ansible-tmp-1550180925.73-263417387907116\dns.ps1 [{"state": "presen …”,
“+ ~”,
“Unexpected token ‘:’ in expression or statement.”,
“”,
“At line:1 char:214”,
“+ … , "zone": "test.com”, "target": "1.2.3.4"}, {"state": "presen …",
“+ ~”,
“Unexpected token ‘:’ in expression or statement.”,
The server the PS script is running on is Windows 2012 R2 - PS version 5.1
I’m running Ansible 2.7.1
Thanks for reading and any assistance offered.