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"
        },


On Friday, 18 September 2020 at 07:30:47 UTC+1 [email protected] wrote:

> 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.
>
> On Thursday, 17 September 2020 at 21:23:15 UTC+1 [email protected] wrote:
>
>> 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.
>>
>> On Thursday, September 17, 2020 at 9:01:23 PM UTC+10 [email protected] 
>> wrote:
>>
>>> Just an FYI there may be a bug with fact_path that I've opened 
>>> 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.
>>> On Thursday, September 17, 2020 at 8:50:48 PM UTC+10 [email protected] 
>>> wrote:
>>>
>>>> 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.
>>>>
>>>>
>>>>
>>>> On Thursday, September 17, 2020 at 4:35:37 PM UTC+10 [email protected] 
>>>> wrote:
>>>>
>>>>> 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!
>>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b30367f3-a389-4f5e-8f84-319fbc85151an%40googlegroups.com.

Reply via email to