Closed usergoodvery closed 7 years ago
OK I think the problem above is with "name: my_rule", as that needs to be made unique for every invocation of the loop eg "name: myrule{{ item }}"
You are correct. Name needs to be unique if you want to add multiple rules.
What you can do is something like this:
- set_fact:
myhosts_ips: '{{ groups[myhosts] | map("extract", hostvars, ["ansible_ssh_host"]) | list }}'
- name: "..."
iptables_raw:
name: my_rule
state: '{{ db_port | ternary("present", "absent") }}'
rules: -A INPUT -p tcp -s {{ myhosts_ips | join(",") }} --dport {{ db_port }} -j ACCEPT
But myhosts
needs to be a group of hosts in the Ansible inventory.
nice one.. thanks
hi is this syntax supported, specifically the use of 'with_items'? It seems only one rule is saved per invocation.