---

- name:  Handle crowdsec port in the firewall
  iptables_raw:
    name: "{{ item.name }}"
    state: "{{ (item.src_ip | length > 0) | ternary('present','absent') }}"
    rules: "-A INPUT -m state --state NEW -p tcp --dport {{ item.port }} -s {{ item.src_ip | join(',') }} -j ACCEPT"
  loop:
    - name: cs_lapi_port
      port: "{{ cs_lapi_port }}"
      src_ip: "{{ cs_lapi_src_ip }}"
    - name: cs_prometheus_port
      port: "{{ cs_prometheus_port }}"
      src_ip: "{{ cs_prometheus_src_ip }}"
  tags: firewall,cs
