From b3e26a435e5b5b05be5b3263c854dd69cb3e172f Mon Sep 17 00:00:00 2001 From: Philipp Rintz Date: Tue, 1 Dec 2020 16:17:01 +0100 Subject: [PATCH] Allow for undefined group variables for merged_groups. --- tasks/main.yml | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 02d08c1..a4bdfa0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,22 +3,34 @@ # # tasks file for nftables -- name: Import nftables-variables if merged_groups is set - when: merged_groups - include_vars: - file: "{{ merged_groups_dir ~ groupname }}" - name: "{{ groupname }}" +- name: Check for group files + become: no + delegate_to: localhost + stat: + path: "{{ merged_groups_dir ~ groupname }}" + register: nftable_group_rules loop: "{{ group_names }}" loop_control: loop_var: groupname -- name: Combine Rules when merged_groups is set - when: merged_groups and hostvars[inventory_hostname][groupname]|length > 0 - set_fact: - nft_combined_rules: "{{ nft_combined_rules | default({}) | combine ( hostvars[inventory_hostname][groupname], recursive=True ) }}" - loop: "{{ group_names }}" +- debug: var=nftable_group_rules + +- name: Import nftables-variables if merged_groups is set + when: merged_groups and varfile.stat.exists + include_vars: + file: "{{ merged_groups_dir ~ varfile.groupname }}" + name: "{{ varfile.groupname }}" + loop: "{{ nftable_group_rules.results }}" loop_control: - loop_var: groupname + loop_var: varfile + +- name: Combine Rules when merged_groups is set + when: merged_groups and (hostvars[inventory_hostname][varfile.groupname] is defined and hostvars[inventory_hostname][varfile.groupname]|length > 0) and varfile.stat.exists + set_fact: + nft_combined_rules: "{{ nft_combined_rules | default({}) | combine ( hostvars[inventory_hostname][varfile.groupname], recursive=True ) }}" + loop: "{{ nftable_group_rules.results }}" + loop_control: + loop_var: varfile - name: Load specific OS vars for nftables include_vars: "{{ osname }}"