Configurable fact path (#18147)

* Make fact_path configurable

* Add docs for fact_path

* Add tests for localfacts

* Default fact gathering settings in PlayContext
This commit is contained in:
Alvaro Aleman 2017-01-12 16:49:04 +01:00 committed by Brian Coca
commit 1b2ad94496
8 changed files with 73 additions and 3 deletions

View file

@ -129,3 +129,48 @@
- 'ansible_interfaces|default("UNDEF_NET") != "UNDEF_NET"'
- 'ansible_mounts|default("UNDEF_HW") == "UNDEF_HW"'
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"'
- hosts: facthost9
tags: [ 'fact_local']
connection: local
gather_facts: no
tasks:
- name: Create fact directories
become: true
with_items:
- /etc/ansible/facts.d
- /tmp/custom_facts.d
file:
state: directory
path: "{{ item }}"
mode: '0777'
- name: Deploy local facts
with_items:
- path: /etc/ansible/facts.d/testfact.fact
content: '{ "fact_dir": "default" }'
- path: /tmp/custom_facts.d/testfact.fact
content: '{ "fact_dir": "custom" }'
copy:
dest: "{{ item.path }}"
content: "{{ item.content }}"
- hosts: facthost9
tags: [ 'fact_local']
connection: local
gather_facts: yes
tasks:
- name: Test reading facts from default fact_path
assert:
that:
- '"{{ ansible_local.testfact.fact_dir }}" == "default"'
- hosts: facthost9
tags: [ 'fact_local']
connection: local
gather_facts: yes
fact_path: /tmp/custom_facts.d
tasks:
- name: Test reading facts from custom fact_path
assert:
that:
- '"{{ ansible_local.testfact.fact_dir }}" == "custom"'