Infrastructure Variables

How are you storing your infrastructure variables to be reused in your automations?

I define Infrastructure variables as the list of hypervisors you may deploy to a VM to. Or the list of subnets you may deploy a VM to depending on what application is going to be installed.

I’m currently using a role and storing the variables in yaml files.

The role itself has one task that uses ansible.builtin.include_vars

I ingest these variables by including this role.

I’m just wondering how others are doing this.

We’ve done it a few ways:

  • YAML or JSON stored in the project and called into a local variable or fact
  • Stored in an inventory if we’re going to call out to that hypervisor or cloud as the target of the playbook/job template
  • Hash tables embedded directly into the playbook that we then do lookups off of (we’ve moved away from this due to maintainability issues)
  • Custom middleware system that we developed which allows us to use Excel/CSV files in Sharepoint as a data source (the replacement for the hash table method)
  • Stored as extra_vars on the job/workflow template (AWX/AAP)
  • Custom credential type if the data is sensitive (AWX/AAP, Ansible Vault would probably be the CLI analog for this)

I haven’t really found a “wrong” way to do this (although I’m sure someone will disagree). What we tried to account for is the team’s ability to maintain the data, the sensitivity of the data and how it’s intended to be used.

Some of these may also depend on if you’re primarily doing ansible-playbook/ansible-navigator from the CLI or if you’re an AWX/AAP user.

Best regards,

Joe

1 Like