Interview Prep/Ansible/Variables, Facts and Templates

A fact you need is not collected by default, such as a custom application version.

IntermediateScenarioVariables, Facts and Templates
Answer

Situation read → Extend facts.

What I'd do → Drop a script or JSON into /etc/ansible/facts.d/ on the target.

- ansible.builtin.copy:
    dest: /etc/ansible/facts.d/app.fact
    content: '{"version": "{{ app_version }}"}'
    mode: "0644"
- ansible.builtin.setup:
    filter: ansible_local

Then use ansible_local.app.version.

Why → Files ending in .fact (JSON, INI or an executable printing JSON) become ansible_local.

Interview tip → Re-run setup after creating the file to refresh within the same play.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Templates