• 0 Posts
  • 17 Comments
Joined 2 years ago
cake
Cake day: July 14th, 2023

help-circle
  • I try some tests based on your description, and I think I got a solution. Try to use host_vars

    This is a playbook:

    ---
    - name: Test for lemmy
      hosts: your_hosts
      vars:
        networks:
          ext:
            ipv4: "127.0.0.1"
      tasks:
        - name: Use template
          ansible.builtin.template:
            src: test.j2
            dest: "/etc/iptables/rules.v4"
            owner: root
            group: root
            mode: "0644"
    

    This is a template file test.j2:

    {% for rule in rules %}
    {{ rule }}
    {% endfor %}
    

    This is a host2.yml file in a host_vars directory:

    ---
    rules:
      - "-A INPUT -p tcp -s {{ networks['ext']['ipv4'] }} --dport 6000 -j ACCEPT"
    

    For another hosts you can create separate host files with variable rules.