Sam Anthony
Sam Anthony

Reputation: 1749

facts.d folder not working as expected

Cannot seem to discover facts from facts.d folder. Here is my setup. All the files mentioned are on my OSX machine which has ansible installed. Running playbook against remote machine

file: /work/myproject/ansible.cfg

[default]
fact_path=/work/myproject/facts.d

file: /work/myproject/facts.d/info.fact (static file)

myvar=myvalue

command output: ansible --version

ansible 2.4.0
  config file = /work/myproject/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 

file: /work/myproject/test.yml (playbook)

- name: Testing
  gather_facts: true
  hosts: all
  user: root
  roles:
    - role: test

command output: ansible-playbook -i hosts test.yml --limit=dev

....
.... 'myvar' is undefined
....

Cant seem to use {{myvar}} in tasks like I would expect.

Can anyone spot the problem, or at least suggest some commands/tools to diagnose the problem?

Upvotes: 1

Views: 1966

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68239

All the files mentioned are on my OSX machine which has ansible installed

But facts.d directory should be on the managed host.

From the docs:

If a remotely managed system has an /etc/ansible/facts.d directory, any files in this directory ending in .fact, can be JSON, INI, or executable files returning JSON, and these can supply local facts in Ansible. An alternate directory can be specified using the fact_path play directive.

Update to answer comment:

Documentation excerpt about accessing facts.d facts:

And this data can be accessed in a template/playbook as: {{ ansible_local.preferences.general.asdf }}

Upvotes: 4

Related Questions