diff --git a/using-facts/ansible.cfg b/using-facts/ansible.cfg new file mode 100644 index 0000000..1f25df3 --- /dev/null +++ b/using-facts/ansible.cfg @@ -0,0 +1,4 @@ +[defaults] +fact_caching = jsonfile +fact_caching_connection = facts +fact_caching_timeout = 10 diff --git a/using-facts/cacheable-facts.yaml b/using-facts/cacheable-facts.yaml new file mode 100644 index 0000000..14faee5 --- /dev/null +++ b/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'" diff --git a/using-facts/facts/.gitignore b/using-facts/facts/.gitignore new file mode 100644 index 0000000..f59ec20 --- /dev/null +++ b/using-facts/facts/.gitignore @@ -0,0 +1 @@ +* \ No newline at end of file diff --git a/using-facts/standard-facts.yaml b/using-facts/standard-facts.yaml new file mode 100644 index 0000000..dd976de --- /dev/null +++ b/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"