Storing custom data

Hi,

I’m finding myself running into a problem of where to store Apache / Nginx vhosts. I originally planned to abstract the template to a point I could customise it with variables, but that proved a waste of time because they’re so different from one another.

What’s the best way to go about this problem?

I’m undecided if it’s a good idea to store them in a roles “files/” directory and just copy over the ones I need or do something more advanced.

Any real world uses cases would be appreciated.

Kind Regards,
-Mathew Davies.

One solution could be to use a variable in the path for the template source. The variable name could be a hostname or some other fact, or a variable you set in groupvars.

For example, the files could be stored as:

templates/foo/test.tmpl
templates/bar/test.tmpl

Playbook:

vars:

  • test1: foo
  • test2: bar

tasks:

  • template: src=templates/{{test1}}/test.tmpl dest=/tmp/foo.out
  • template: src=templates/{{test2}}/test.tmpl dest=/tmp/bar.out