Search code examples
ansibleansible-facts

Ansible: Custom facts - error loading facts as JSON or ini


shell> ansible ubuntu-c -m setup -m "filter=ansible_local"
...

I am trying to practice Ansible Custom facts: /etc/ansible/facts.d/try.fact

#!bin/bash
echo {\""thing\"" : \""value\""}

But in keep getting this error:

"try": "error loading facts as JSON or ini - please check content: /etc/ansible/facts.d/try.fact" 

thought when i try to excute it using :

sh ./etc/ansible/facts.d/try.fact

it returns the correct JSON format:

shell> sh /etc/ansible/facts.d/try.fact
{"thing": "value"}

Solution

  • As noted in the documentation, the file should be marked as executable if you want it to be executed, otherwise it is treated as a static file containing structured data. To test this you should be executing the file directly (/etc/ansible/facts.d/try.fact), not passing it to sh.

    chmod +x /etc/ansible/facts.d/try.fact
    /etc/ansible/facts.d/try.fact