# windows custom facts help

**URL:** <https://forum.ansible.com/t/windows-custom-facts-help/33835>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [September 17, 2020, 6:35am UTC](https://forum.ansible.com/t/windows-custom-facts-help/33835 "2020-09-17T06:35:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dennis\_McCarthy1](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Dennis\_McCarthy1](https://forum.ansible.com/u/Dennis_McCarthy1)\
**Post date:** [September 17, 2020, 6:35am UTC](https://forum.ansible.com/t/windows-custom-facts-help/33835/1 "2020-09-17T06:35:36Z")

</div>

Can anyone point me in the direction of how to setup custom/local facts on Windows please? not just use fact\_path…

Reading the docs I’ve found so far, it looks like you can’t just have a file with key:value like Linux under the heading [local\_facts] for example (unless you can? but setup doesn’t pick up the values when i run ansible setup against the windows host). The docs/google suggest you need to add .ps1 scripts to a directory (fact\_path DIR) and then get JSON output of the facts you want to know about.

That sounds ok as it’s similar to creating a dynamic inventory, but can anyone share what the output looks like? Better yet, if anyone knows where a document is that explains this process that would be great.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [September 17, 2020, 10:50am UTC](https://forum.ansible.com/t/windows-custom-facts-help/33835/2 "2020-09-17T10:50:48Z")

</div>

Just try it out and see for yourself. I have placed the following script at C:\Windows\TEMP\facts\my\_facts.ps1 with the contents

@{  
my\_custom\_fact = ‘value’  
my\_complex\_custom\_fact = @{  
hello = ‘world’

}

} | ConvertTo-Json -Compress

This script converts a PowerShell hashtable (like a dictionary) to a JSON and outputs it for the setup module to collect.

Then run ‘ansible windows -m setup -a fact\_path=C:/Windows/TEMP/facts’ and look at the output.

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [September 17, 2020, 11:01am UTC](https://forum.ansible.com/t/windows-custom-facts-help/33835/3 "2020-09-17T11:01:23Z")

</div>

Just an FYI there may be a bug with fact\_path that I’ve opened [https://github.com/ansible-collections/ansible.windows/issues/106](https://github.com/ansible-collections/ansible.windows/issues/106). I’m not sure if this bug can be easily fixed so stay tuned to that. Another option if you have custom facts is to create your own fact module. They are quite simple to do as well.

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [September 17, 2020, 8:23pm UTC](https://forum.ansible.com/t/windows-custom-facts-help/33835/4 "2020-09-17T20:23:15Z")

</div>

A further FYI, do not include the | ConvertTo-Json part, just output the hashtable or array directory, the issue has been updated with more information as to why that is.

---

<div class="post-metadata">

**Author:** ![Dennis\_McCarthy1](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Dennis\_McCarthy1](https://forum.ansible.com/u/Dennis_McCarthy1)\
**Post date:** [September 18, 2020, 6:30am UTC](https://forum.ansible.com/t/windows-custom-facts-help/33835/5 "2020-09-18T06:30:47Z")

</div>

Hi, yes this works:

Thanks! this was just what I was looking for.

I made some updates and added command output to a variable which was very helpful. I’ll add the rest in later:

**$InstanceType = $(Invoke-RestMethod -uri [http://169.254.169.254/latest/meta-data/instance-type](http://169.254.169.254/latest/meta-data/instance-type))**  
@{  
cloud = ‘AWS’  
**Instance\_type = $InstanceType**  
AVAIL\_ZONE = ‘eu-west-3a’  
REGION = ‘eu-west-3’  
environment = ‘DIT’  
Support\_Team = ‘Win\_Team’  
Callout = ‘6-8’  
my\_custom\_fact = ‘value’  
}

Which gave this output in setup:

“ansible\_local”: {  
“AVAIL\_ZONE”: “eu-west-3a”,  
“Callout”: “6-8”,  
“REGION”: “eu-west-3”,  
“Support\_Team”: “Win\_Team”,  
“cloud”: “t2.micro”,  
“environment”: “DIT”,  
“my\_custom\_fact”: “value”  
},

One last question, is it possible to make it look like this like it does on Linux (adding the filename and the [title] block)?:

“ansible\_local”: {  
**“local”: {**  
**“local\_facts”: {**  
“ami\_id”: “ami-0701e7be9b2a77600”,  
“avail\_zone”: “eu-west-1b”,  
“region”: “eu-west-1”,  
“callout”: “24-7”,  
“environment”: “Production”,  
“instance\_type”: “t2.micro”,  
“support\_team”: “Hadoopi\_Team”,  
“cloud”: “AWS”  
**}**  
**}**  
},

I tried to add in additional lines but it didn’t like it and I’m pretty sure it’s a simple fix.

Thanks again.

---

<div class="post-metadata">

**Author:** ![Dennis\_McCarthy1](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Dennis\_McCarthy1](https://forum.ansible.com/u/Dennis_McCarthy1)\
**Post date:** [September 18, 2020, 6:52am UTC](https://forum.ansible.com/t/windows-custom-facts-help/33835/6 "2020-09-18T06:52:04Z")

</div>

my output missed out the new variableoutput, this is it:

“ansible\_local”: {  
“AVAIL\_ZONE”: “eu-west-3a”,  
“Callout”: “6-8”,  
**“Instance\_type”: “t2.micro”, ← variable output**  
“REGION”: “eu-west-3”,  
“Support\_Team”: “Win\_Team”,  
“cloud”: “AWS”,  
“environment”: “DIT”,  
“my\_custom\_fact”: “value”  
},

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [September 18, 2020, 7:30pm UTC](https://forum.ansible.com/t/windows-custom-facts-help/33835/7 "2020-09-18T19:30:24Z")

</div>

The behaviour of the fact names is hard coded, it cannot change without breaking others who use ‘fact\_path’ on Windows. If you desire a custom fact layout then you should create your own fact PowerShell module and run that.
