- set_fact: group_identifier: "{{ item }}" value: "{{ nftables.rules.files[item] }}" when: "item is defined" #'': '' - block: - name: Create main rule file template: src: "{{ value }}" dest: "/etc/nftables/ansible-managed/{{ group_identifier }}.nft" when: value is string #'': # main: # '': '' - block: - set_fact: items: "{{ nftables.rules.files[item] }}" - block: - name: Create main rule file template: src: "{{ items['main'] }}" dest: "/etc/nftables/ansible-managed/{{ group_identifier }}.nft" - name: Include rule files lineinfile: path: "/etc/nftables/ansible-managed/{{ group_identifier }}.nft" regexp: "include\\s+(\"|')\\/etc\\/nftables\\/ansible-managed\\/{{ group_identifier }}\\/.*$" line: 'include "/etc/nftables/ansible-managed/{{ group_identifier }}/*.nft"' when: items['main'] is defined - name: Create group folder file: path: "/etc/nftables/ansible-managed/{{ group_identifier }}/" state: directory when: items|length > 0 - set_fact: test: "{{ items | dict2items | selectattr('key', 'ne', 'main') }}" - name: Create included rule files template: src: "{{ fileItem.value }}" dest: "/etc/nftables/ansible-managed/{{ group_identifier }}/{{ fileItem.key }}.nft" loop: "{{ items | dict2items | selectattr('key', 'ne', 'main') }}" loop_control: loop_var: fileItem when: value is mapping