Ansible: set_fact cannot access facts created in the same step
Using Ansible and the set_fact module, it is possible to set multiple facts within the same step, e.g.
I discovered though that it is not possible to set multiple facts within the same step, if one of them references another created in the same step. For example, something like the following where results_a and results_b are both used to determine total_results:
This will generate an error similar to the following:
“msg”: “The task includes an option with an undefined variable. The error was: ‘results_a’ is undefined….
Some research reveals that this is due to an unordered dictionary being used, so it would not be possible to guarantee that either or both of results_a and results_b being available at the time of calculation of total_results . More details here: https://github.com/ansible/ansible/issues/40239
To get around the problem, multiple steps need to be used: