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.
More on Variables, Facts and Precedence
Where can you define variables in Ansible?BeginnerHow do you reference a variable, and when must you quote it?BeginnerGive a summary of variable precedence.IntermediateWhat are the lowest and highest precedence sources, and why does that matter?IntermediateWhat is the difference between a role's `defaults/` and `vars/`?IntermediateWhat are facts and how are they gathered?Beginner