For the last few weeks I’ve been using Ansible quite extensively, and I realized for the first time that facts set in roles are not locally scoped. It so happens I like to name my variables as generically as the context permits, so instead of opting for prefixing all my role variables with company and role name, I tried something else.
I’ve documented a proof of concept on GitHub that aims to provide roles with a locally scoped fact named local
, allowing one to create simply named facts without worry of them being overwritten by including roles.
I’ve been looking around for similar approaches, but did not find them, which leaves me to wonder whether I’m missing something about Ansible that makes the proposal unnecessary.
My question is basically whether the proposal is viable as a solution, or, alternatively, there are important reasons not to go down this path.
Edit: I realized that it might be very desirable to allow local scope without changing the way the role is consumed, so I added a set of roles that demonstrate this.