Why Ansible set_fact Persists Between Roles (And How to Reset It)
You set a variable with set_fact inside a role. It works perfectly. Then you run the same role again — either in a loop, or later in the same playbook — and it behaves differently. The variable has a value from the previous run that you didn’t expect. This is one of Ansible’s most common gotchas. Here’s exactly why it happens and how to fix it. Why set_fact Persists In Ansible, set_fact sets a variable at the host level for the duration of the play. It is not scoped to the role or task file that created it. Once set, it stays set until: ...