In Ansible I can use a task such as:
- name: Gather the package facts package_facts: manager: auto
to gather the package facts and a condition such as:
when: "'foobar' in ansible_facts.packages"
to only execute a task when package
foobar is installed. Gathering the package facts is a rather lengthy process compared to many of the other tasks in my playbooks.
For the sake of this question we can also assume that instead of
manager: auto I'm using
Now I was unable to find any information regarding if or when the fact
ansible_facts.packages gets invalidated after a subsequent package manager operation and a look at the fact via
debug module doesn't give me any indication as to when it was gathered. Similarly I found no obvious way of checking against the cache time of the package manager. So in essence I was unable to come up with a means of only gathering (or re-gathering) the package facts when necessary.
- does the
ansible_facts.packagesfact get invalidated after subsequent package manager operations?
- if not: how can I get close to the desired "only gather package facts if something changed"?
NB: according to
ansible --version I am running version 2.10.7.