Trying to setup custom facts for Windows. In this case, the powershell info that is shown in $PSVersionTable.
I have tasks to put it all into place and looking at the -vvvv output I do see the information encoded into setup module output. But’s encoded differently then the native facts, example below highlighted in red.
ok: [win10fusion] => {
“ansible_facts”: {
“ansible_PSVersionTable”: “{"Major":5,"Minor":0,"Build":10586,"Revision":494,"MajorRevision":0,"MinorRevision":494}”,
“ansible_architecture”: “64-bit”,
“ansible_bios_date”: “07/01/2015”,
“ansible_bios_version”: “6.00”,
“ansible_date_time”: {
“date”: “2016-08-04”,
“day”: “04”,
“epoch”: “1470354713.15218”,
“hour”: “23”,
“iso8601”: “2016-08-05T04:51:53Z”,
“iso8601_basic”: “20160804T235153120933”,
“iso8601_basic_short”: “20160804T235153”,
“iso8601_micro”: “2016-08-05T04:51:53.120933Z”,
“minute”: “51”,
“month”: “08”,
“second”: “53”,
“time”: “23:51:53”,
“tz”: “Central Standard Time”,
“tz_offset”: “-05:00”,
“weekday”: “Thursday”,
“weekday_number”: “4”,
“weeknumber”: “31”,
“year”: “2016”
},
http://jsonlint.com says the output is valid json, even with the quotes are being escaped.
And it’s encoded as a string?
Here is the powershell script that generates the facts.
$PSVersionTable.PSVersion | ConvertTo-Json -Compress
I thought ansible_PSVersionTable would be a dictionary, like:
“ansible_PSVersionTable”: {"Major":5,"Minor":0,"Build":10586,"Revision":494,"MajorRevision":0,"MinorRevision":494}
The documentation notes says, “… Ansible will take care of this …”
http://docs.ansible.com/ansible/setup_module.html
If the target host is Windows you can now use fact_path. Make sure that this path exists on the target host. Files in this path MUST be PowerShell scripts (*.ps1) and their output must be formattable in JSON (Ansible will take care of this). Test the output of your scripts. This option was added in Ansible 2.1.
What does that mean?
Do I not have to “| ConvertTo-Json” ?
Thanks.