Storing env-specific files in inventories

Hi,

We are transitioning from Ansible to AWX. In the past we used to store our env-specific files (production, staging, …) in different env-specific inventories, in a special files folder.

Old structure:

/roles/role_name/tasks/main.yml
/inventories/production/files/config.binary

In my tasks, I was referencing this file using {{ inventory_dir }}/files/config.binary.

Now within AWX we import the inventory as an SCM project and it seems that, when importing, all these additional unconventional files aren’t taken into account.

What’s the proper way to store/retrieve env-specific files?

I don’t want to store these files within my role. This would mean that I’d have to suffix them with the name of my environments.

Thanks,
Alessandro

Hi Allesandro,

Please see my answers inline below.

Hi,

We are transitioning from Ansible to AWX. In the past we used to store our env-specific files (production, staging, …) in different env-specific inventories, in a special files folder.

Old structure:

/roles/role_name/tasks/main.yml
/inventories/production/files/config.binary

In my tasks, I was referencing this file using {{ inventory_dir }}/files/config.binary.

One question for you w.r.t what you described above: how did you make the difference between production and staging when running Ansible before AWX? I understand you have a special ‘files’ folder but your inventory file itself does not seem to be different between staging/production, etc or is it? Giving ansible-playbook invocation commandlines in both cases would help here.

Now within AWX we import the inventory as an SCM project and it seems that, when importing, all these additional unconventional files aren’t taken into account.

Yes, that does not surprise me. On AWX 19.4 (not tested w/ the lastest AWX versions), inventory import was the result of calling the ansible-inventory command on your inventory files and storing that into the AWX DB.
This was causing us some issues, esp w.r.t --extra-vars usage (you can look for my previous posts on this list for more information). I am thus not surprised that your other files are ignored.

This is a big difference from standard ansible-playbook in that inventory parsing is done in AWX as a separate step via ansible-inventory.

What’s the proper way to store/retrieve env-specific files?

I don’t want to store these files within my role. This would mean that I’d have to suffix them with the name of my environments.

I don’t know if you were specifiying a different inventory file between production and staging, etc (cf my question above) but if that is the case, maybe you could add a new key into your inventory file itself with the contents of the ‘config.binary’ in base64. Then you could reference it via hostvars syntax?

HTH,

Vincent