Browse Source

Using facts

master
Nicolas Massé 8 years ago
parent
commit
5efb055375
  1. 4
      using-facts/ansible.cfg
  2. 17
      using-facts/cacheable-facts.yaml
  3. 1
      using-facts/facts/.gitignore
  4. 23
      using-facts/standard-facts.yaml

4
using-facts/ansible.cfg

@ -0,0 +1,4 @@
[defaults]
fact_caching = jsonfile
fact_caching_connection = facts
fact_caching_timeout = 10

17
using-facts/cacheable-facts.yaml

@ -0,0 +1,17 @@
---
- name: A cacheable fact can be defined and used between invocations / playbooks
gather_facts: no
hosts: localhost
tasks:
- debug:
var: myfact456
- set_fact:
myfact456: test
cacheable: true
when: myfact456 is not defined
- assert:
that:
- "myfact456 == 'test'"
- "'myfact456' in ansible_facts"
- "ansible_facts.myfact456 == 'test'"

1
using-facts/facts/.gitignore

@ -0,0 +1 @@
*

23
using-facts/standard-facts.yaml

@ -0,0 +1,23 @@
---
- name: A standard fact can be defined in a playbook...
gather_facts: no
hosts: localhost
tasks:
- set_fact:
myfact123: test
- assert:
that:
# A fact is available as a standard variable
- "myfact123 == 'test'"
# But not part of the "ansible_facts" dictionary
- "'myfact123' not in ansible_facts"
- name: and used in another role/playbook !
gather_facts: no
hosts: localhost
tasks:
- assert:
that:
- "myfact123 == 'test'"
- "'myfact123' not in ansible_facts"
Loading…
Cancel
Save