I am configuring network ports for an app and accordingly firewall rules as followed:
host_vars/hostXX.yaml:
cluster_nodes:
- map: TheIsland
user: theisland
network:
game_port: 7777
query_port: 27015
rcon_port: 27020
iptables_rules:
- rule:
chain: INPUT
interface: enp98s0f0
protocol: tcp
destination_port: 27020
jump: ACCEPT
- rule:
chain: INPUT
interface: enp98s0f0
protocol: udp
destination_port: 7777
jump: ACCEPT
- rule:
chain: INPUT
interface: enp98s0f0
protocol: udp
destination_port: 27015
jump: ACCEPT
What I would like to achieve is, that I want to define a hash with all network ports and then reference to that for the configuration of the application and the firewall:
ark_cluster_ports:
theisland:
game_port: 7777
query_port: 27015
rcon_port: 27020
cluster_nodes:
- map: TheIsland
user: theisland
network:
game_port: > reference to ark_cluster_ports.theisland.game_port
query_port: > reference to ark_cluster_ports.theisland.query_port
rcon_port: > reference to ark_cluster_ports.theisland.rcon_port
iptables_rules:
- rule:
chain: INPUT
interface: enp98s0f0
protocol: tcp
destination_port: reference to ark_cluster_ports.theisland.rcon_port
jump: ACCEPT
- rule:
chain: INPUT
interface: enp98s0f0
protocol: udp
destination_port: reference to ark_cluster_ports.theisland.game_port
jump: ACCEPT
- rule:
chain: INPUT
interface: enp98s0f0
protocol: udp
destination_port: reference to ark_cluster_ports.theisland.query_port
jump: ACCEPT
What I tried so far is anchors and the merge operator:
ark_cluster_ports: &ark_cluster_ports
theisland:
game_port: 7777
query_port: 27015
rcon_port: 27020
cluster_nodes:
- map: TheIsland
user: theisland
network:
<<: *ark_cluster_ports.theisland
And lookup with dictionary:
ark_cluster_ports:
theisland:
game_port: 7777
query_port: 27015
rcon_port: 27020
cluster_nodes:
- map: TheIsland
user: theisland
network: "{{ lookup('dict', ark_cluster_ports.theisland) }}"
But it seems that I am totally wrong... Could someone point me into the right direction?
Thanks a lot and best regards, michael