I've written an nftables role for ansible that opens me ports for my servers. I would like to have some kind of hierarchical system. I would like to define rules that shall be opened on every host but some rules shall only be applied to a group of hosts.
Inventory
---
myservers:
hosts:
server1:
server2:
server3:
server4:
groupa:
hosts:
server1:
server2:
groupb:
hosts:
server3:
server4:
Those are my group_vars: myservers.yml
---
nftablesopen:
- dport: "22"
comment: "SSH"
proto: tcp
groupa.yml
---
nftablesopen:
- dport: "123"
comment: "NTP"
proto: "udp"
groupb.yml
---
nftablesopen:
- dport: "80"
comment: "HTTP"
proto: "udp"
When I run the playbook the varible priorities kick in and only a fragment of what I've defined is being applied. What is the best approach in Ansible to handle this? I'd rather not make plenty of different variables that I merge into a single one because I don't want to update my tasks when I add a new group of hosts for example. Can't I just append items to an already existing list of items, just like it's being done in different programming languages?