Hello list!
I’m wondering how you would go about organizing things when you can have several instance of the same kind of application on the same host.
Let me give you an example to make things clearer.
Let’s say with have 3 hosts, with 2 clusters of 2 appservers each.
That would give us something like:
- cluster1
– appserver1 on host1
– appserver2 on host2 - cluster2
– appserver3 on host1
– appserver4 on host3
We could have some configuration that is at the cluster level (external_url).
Also some at the appserver level (http_port).
Potentially, we could also have some default defined at the cluster level but overriden at the appserver level (kind of what exists with groups/hosts).
Now, when we run our playbook, we can’t just have “http_port” defined in group or host vars, because we’d have a conflict on the http_port on host1 which has both appserver1 and appserver3 (for both of which we want to use the same appserver.yml playbook)
So, basically, how would you map an application-centric configuration to the host-centric one we have in ansible (and other configuration tools, the logic is pretty much the same) ?
One idea I had was to actually not use groups/hosts as they were intended but use them as clusters/appservers with a delegate_to to the actual host on each task, but that seems very much a big hack and is probably very inefficient as we’d keep establishing new connections to the actual hosts all the time.
Another idea was nested includes + with_items with vars_files, but I don’t think that’s possible, something like:
- main.yml:
- include: cluster.yml cluster=${item}
with_items: ${clusters}
- cluster.yml:
- include: appserver.yml appserver=${item}
with_items: ${cluster.appservers}
only_if: “${item.host} == ${host}”
vars_files: myvars/clusters/${cluster.id}.yml, myvars/appservers/${item.id}.yml
At this point, I’m kinda stumped about what direction I should take among those (if any), and starting to have knots in my brain
I’d appreciate any ideas/suggestions (other than “don’t put two instances of the same kind of application on the same host”).