Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overlapping groups and their firewall rules #33

Open
patrickdeelman opened this issue Apr 20, 2018 · 1 comment
Open

overlapping groups and their firewall rules #33

patrickdeelman opened this issue Apr 20, 2018 · 1 comment

Comments

@patrickdeelman
Copy link

I run a complex ansible setup with many hosts and many overlapping groups. It sometimes happens that i have variables overlapping in my group_vars. I find myself not wanting to enable merge=yes in my ansible config so i kind of altered the iptables template.

Note: this only works with ansible version >= 2.5 due to the vars lookup. Also there are quite a lot of deprecation notices when running ansible 2.5 because of the when statements. You should use "result is changed" instead of the current "result|changed" (gotta love the ansible team ;) )

{% set merged = {} %}
{% set found_groups = hostvars[inventory_hostname].keys() | to_json | from_json | json_query('[?starts_with(@, 'firewall_v4_group')]') | sort %}

{% for rules in (['firewall_v4_default_rules'] + found_groups + ['firewall_v4_host_rules']) %}
{% set _ = merged.update(lookup('vars', rules)) %}
{{ rules }}
{% endfor %}

This way i can have 2 roles assigned to a host, lets say role_kafka and role_zookeeper and keep the firewall rules in seperate group files without having ansible overwrite the variable with whatever comes last.

@patrickdeelman
Copy link
Author

ps. The from_json | to_json is a small hack because the array emmited isn't compatible with json_query somehow. I had the bug somewhere and it was confirmed last month, so it should be fixed pretty soon anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant