I would like to create an Ansible Module that can be used to lookup variables of a given role.
Background:
Our build Git repository is organized in away that we have one Ansible role per micro service (built repo). Those roles have the “default/main.yml”, through which we define a number of default values for the role itself and the variables we override for the “dependencies” roles.
For example, numerious roles have the variable “myrole.python.version”, which typically holds a reference to the respective global version variable that lives in our global variables file. Note, this variables file is available during runtime by the use of the “vars_files” module directive in the initial playbook. So typically, such variable in “default/main.yml” would look like.
myrole:
python:
version: “{{ our.global.vars.python.version }}”
This all works fine when we execute a playbook to build a particular service as it can interpolate those values.
Note, although the majority of those version values are referenced as outline above, some of them are hard coded by assigning a string value (i.e. “1.2.3”) instead of the global variable reference.
Use Case:
In our particular use case, we would like to implement version auditing so we have a complete overview on which versions are used across all our micro services. In order to do this reliably, we need to lookup and interpolate the variables in the same way as a playbook play would see them.
Questions:
How would you implement this?
We thought of creating an Ansible module that plays a give playbook programmatically with the “–check” option, then somehow capture a given variable and return it. There are quite a few unknowns for us as to how we can achieve this with such approach. In addition it would require quite a bit of computing to produce one variable value as output. What’s your opinion?
Is there a way of interpolating variables, exactly the way Ansible does when playing a playbook, without actually playing an entire playbook?
Your help is much appreciated!