mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 15:41:22 -07:00
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:
parent
f078946ed3
commit
1b2ad94496
8 changed files with 73 additions and 3 deletions
|
@ -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"'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue