-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manage servers defined via multiple groups #96
Comments
You can't use group variables if you want # meta/main.yml
---
dependencies:
- role: debops.nginx
nginx_servers:
- '{{ nginx_server }}' |
Actually, you can, it's just a little more complicated: In nginx_servers: [ '{{ nginx_backend_server }}' ]
nginx_backend_server:
name: [ 'backend.{{ ansible_domain }}' ]
enabled: True In nginx_servers: [ '{{ nginx_frontend_server }}' ]
nginx_frontend_server:
name: [ '{{ ansible_domain }}', 'www.{{ ansible_domain }}' ]
enabled: True Now, you need to merge them. To do it, you can create a new inventory group for merged hosts: [nginx-merged-hosts:children]
frontend-servers
backend-servers And, in nginx_servers: '{{ nginx_merged_servers }}'
nginx_merged_servers:
- '{{ nginx_frontend_server | d({}) }}'
- '{{ nginx_backend_server | d({}) }}' Now, when you add your host to (All written on the fly, not tested, but I think it should work) As an aside, Ansible stacks variables from different inventory levels (all, group, host) together so that variables from lower lever override the ones from higher level. Unfortunately, group variables have the same "weight" and I believe the last one wins, so to merge them, you need to get a little creative with different variable names. It's good practive to provide defaults (like |
Ok, well there you go! That's a less complicated solution! 😂 |
@carlalexander Since I've got your attention, two ideas I'm thinking about regarding
|
I have not checked the new I like the idea of |
Sure, default server could stay in |
+1 for |
I'm struggling to find a way to realize server configurations that are defined in the group vars of multiple groups but where the inventory maps these groups to the same host.
Details
I have 2 groups (
frontend-servers
,backend-servers
) to which thedebops.nginx
role is applied via the following playbook:Furthermore, I define group variables for both groups:
However, I have an inventory that maps both groups to the same host
It seems like only one of the
nginx_servers
lists from thegroup_vars
is respected. Is there another way to realize servers from multiple groups on the same host?The text was updated successfully, but these errors were encountered: