I've wrestled with Windows custom facts in the past. This is what I do:
This is a test facts file you need to place on your Windows server. I use Ansible to put it in place:
$InstanceType = $(Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/instance-type)
$AvailZone = $(Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/placement/availability-zone)
$AMI_ID = $(Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/ami-id)
@{
local = @{
local_facts = @{
cloud = 'AWS'
instance_type = $InstanceType
avail_zone = $AvailZone
ami_id = $AMI_ID
region = 'eu-west-1'
environment = 'DIT'
Support_Team = 'Win_Team'
Callout = '6-8'
}
}
}
You don't need to nest the local & local_facts, that's just my personal preference.
At the top of the file, I've added a few variables to grab the AWS metadata but you can change these to something else.
I put my file in C:\TEMP\facts
then run ansible:
ansible win -m setup -a fact_path=C:/TEMP/facts
and you should get out something like this:
"ansible_local": {
"local": {
"local_facts": {
"Callout": "6-8",
"Support_Team": "Win_Team",
"ami_id": "ami-07d8c98607d0b1326",
"avail_zone": "eu-west-1c",
"cloud": "AWS",
"environment": "DIT",
"instance_type": "t2.micro",
"region": "eu-west-1"
}
}
},
if you put the JSON into a file, you should be able to query it with a command like this:
cat file1 | jq '.[] .ansible_facts.ansible_local.local.local_facts'
{
"ami_id": "ami-0c95efaa8fa6e2424",
"avail_zone": "eu-west-1c",
"region": "eu-west-1",
"Callout": "6-8",
"environment": "DIT",
"instance_type": "t2.micro",
"Support_Team": "Win_Team",
"cloud": "AWS"
}