Variable in the hosts file?

On any given day I might be accessing different aws systems with different sets of FQDNs.

I’m looking for a way to basically templatize (new word?) the hosts file.

Example:
`
this_track=track4
this_subnet=239

[group1]

ax.$this_track$.ecm ansible_host=10.$this_subnet$.1.5 ansible_ssh_private_key_file=/home/me/.ssh/me_rsa
ca.$this_track$.ecm ansible_host=10.$this_subnet$.1.6 ansible_ssh_private_key_file=/home/me/.ssh/me_rsa

[group2]

if.$this_track$.ecm ansible_host=10.$this_subnet$.1.7 ansible_ssh_private_key_file=/home/me/.ssh/me_rsa
ui.$this_track$.ecm ansible_host=10.$this_subnet$.1.8 ansible_ssh_private_key_file=/home/me/.ssh/me_rsa

`

Ideally I would set the this_track variable at the top of the playbook file, but I’d be OK with something like this.

Any tips appreciated,
Chris.

On any given day I might be accessing different aws systems with different
sets of FQDNs.

I'm looking for a way to basically templatize (new word?) the hosts file.

It's called dynamic inventory

Example:
this_track=track4
this_subnet=239

[group1]

ax.$this_track$.ecm ansible_host=10.$this_subnet$.1.5
ansible_ssh_private_key_file=/home/me/.ssh/me_rsa
ca.$this_track$.ecm ansible_host=10.$this_subnet$.1.6
ansible_ssh_private_key_file=/home/me/.ssh/me_rsa

[group2]

if.$this_track$.ecm ansible_host=10.$this_subnet$.1.7
ansible_ssh_private_key_file=/home/me/.ssh/me_rsa
ui.$this_track$.ecm ansible_host=10.$this_subnet$.1.8
ansible_ssh_private_key_file=/home/me/.ssh/me_rsa

Ideally I would set the this_track variable at the top of the playbook
file, but I'd be OK with something like this.

With a custom script you can do all this and more.

https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html
https://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html