Interview Prep/Ansible/Variables, Facts and Precedence

What does `cacheable: true` on `set_fact` do?

AdvancedConceptVariables, Facts and Precedence
Answer

By default a set_fact value lives only in memory for the current run. With cacheable: true it is also written to the fact cache (if one is configured), so the next run, or another playbook, can read it as a host fact.

- ansible.builtin.set_fact:
    last_deployed: "{{ app_version }}"
    cacheable: true

In the current run it still has set_fact precedence; when loaded from cache in a later run it has host-fact precedence. It does nothing useful without fact_caching set up, and entries expire with fact_caching_timeout.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence