I am trying to change the default path of /etc/ansible/facts.d for storing Custom Facts to a different directory. As of now, if I store my Custom Facts in this path, I can retrieve them along with the default Ansible Facts in the output of
ansible myhost -m setup | less
There is nothing wrong with the Custom Facts and I can see the expected output.
However, if I add the Custom Facts to a different directory, as explained in the documentation, called /home/ansible/facts.d/custom.fact and define its path in the /etc/ansible/ansible.cfg by adding fact_path=/home/ansible/facts.d/ to it, I can no longer see the Custom Facts in the output of ansible myhost -m setup | less.
My ansible.cfg now contains the following:
# (string) This option allows you to globally configure a custom path for 'local_facts' for the implied :ref:`ansible_collections.ansible.builtin.setup_module` task when using fact gathering.
# If not set, it will fallback to the default from the ``ansible.builtin.setup`` module: ``/etc/ansible/facts.d``.
# This does **not** affect user defined tasks that use the ``ansible.builtin.setup`` module.
# The real action being created by the implicit task is currently ``ansible.legacy.gather_facts`` module, which then calls the configured fact modules, by default this will be ``ansible.builtin.setup`` for POSIX systems but other platforms might have different defaults.
fact_path='/home/ansible/facts.d/'
I have also tried removing the single-quotes, replacing this path with ~/facts.d/ and $HOME/facts.d/ but nothing worked.
I also tried defining fact_path=/home/ansible/facts.d/ explicitly in my playbook. However this has not worked out. The playbook now starts in the following way:
---
- hosts: kna
become: yes
ignore_errors: no
fact_path: /home/ansible/AnsibleCustomFacts/facts.d/
gather_facts: yes
# continued playbook
How do I change the fact_path so that I would be able to get get the combined custom and default facts in the output of ansible mygroup -m setup | less?
With an
ansible.cfgfilean existing and accessible Custom Fact path
/home/ansible_user/test/factsand an Custom Fact filetest.factwith content ofa minimal example playbook
will result into an output of
as well an ad-hoc command of
will result into an output of
Summary
In an ad-hoc command one will need to specify the module configuration and parameter arguments separately again, otherwise a command
will result into an output of
if there would be the respective Custom Fact file, or just only
Documentation
Similar Q&A
debugad-hocansible.cfg"