Best practice/way for variables to be used in template?

All,

I’m after some advice here on the best way of getting a template file populated with one or more network ranges based on the host the file is copied onto.

So, basically I’ll have 15+ hosts that will be running a program where one of the configuration files will contain one or more network ranges that varies with the host it is being installed on.

I’m trying to figure out where it is best to store these variables? Would it be in the inventory file or a local variable file for the role I’m creating?

The file looks something like this:

← Cut →

10.0.0.0/8 Private IP space
172.16.0.0/12 Private IP space
192.168.0.0/16 Private IP space
{{ ipranges }}

← Cut →

Where ‘ipranges’ is supposed to be one or more public ranges from the site in question. (I’m not even sure at this stage if I can have ‘multi-value’ variables like this? Ie, one site could have a range of say 1.1.1.1/20 and the other could have two ranges .2.2.2.2/24 and 3.3.3.3/20 and I’d like them to be on one line each)

Have anyone else done something similar to this and have the time to give me a nudge in the correct direction? I’m sort of changing my mind about the best way of doing this as well as which way would be easiest to document/maintain in the long run?

Thanks in advance, Mike

Have you considered using host_vars/group_vars to define the ranges?
Since this sounds like rather natural place to set these values at
(allowing you to more easily reconfigure as needed without touching
role internals).

Best regards

Hi Branko,

Yeah, I stumbled onto host_vars during my trial and error approach so that’s where it all ended up.

Many thanks for getting back to me - confirming my conclusion/finding.

Cheers, Mike