Skip to content

Commit

Permalink
Remove code redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
drybjed committed Jun 20, 2017
1 parent ecfd66b commit d178cbb
Showing 1 changed file with 16 additions and 40 deletions.
56 changes: 16 additions & 40 deletions templates/etc/ferm/rules.d/rule.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -120,59 +120,35 @@
{% endif %}
{% endif %}
{% if config.interface_present|d() %}
{% if config.interface_present is string %}
{% if hostvars[inventory_hostname]["ansible_" + config.interface_present]|d() %}
{% set _ = ferm__tpl_config.update({'interface_present': [ config.interface_present ] }) %}
{% for interface in ([ config.interface_present ] if config.interface_present is string else config.interface_present) %}
{% if hostvars[inventory_hostname]["ansible_" + interface]|d() %}
{% set _ = ferm__tpl_config.update({'interface_present': [ interface ] }) %}
{% endif %}
{% else %}
{% for interface in config.interface_present %}
{% if hostvars[inventory_hostname]["ansible_" + interface]|d() %}
{% set _ = ferm__tpl_config.update({'interface_present': [ interface ] }) %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% elif config.interfaces_present|d() %}
{% if config.interfaces_present is string %}
{% if hostvars[inventory_hostname]["ansible_" + config.interfaces_present]|d() %}
{% set _ = ferm__tpl_config.update({'interface_present': [ config.interface_present ] }) %}
{% for interface in ([ config.interfaces_present ] if config.interfaces_present is string else config.interfaces_present) %}
{% if hostvars[inventory_hostname]["ansible_" + interface]|d() %}
{% set _ = ferm__tpl_config.update({'interface_present': [ interface ] }) %}
{% endif %}
{% else %}
{% for interface in config.interfaces_present %}
{% if hostvars[inventory_hostname]["ansible_" + interface]|d() %}
{% set _ = ferm__tpl_config.update({'interface_present': [ interface ] }) %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% if config.outerface|d() %}
{% set _ = ferm__tpl_config.update({'outerface': ([ config.outerface ] if config.outerface is string else config.outerface) }) %}
{% elif config.outerfaces|d() %}
{% set _ = ferm__tpl_config.update({'outerface': ([ config.outerfaces ] if config.outerfaces is string else config.outerfaces) }) %}
{% endif %}
{% if config.outerface_present|d() %}
{% if config.outerface_present is string %}
{% if hostvars[inventory_hostname]["ansible_" + config.outerface_present]|d() %}
{% set _ = ferm__tpl_config.update({'outerface_present': [ config.outerface_present ] }) %}
{% for outerface in ([ config.outerface_present ] if config.outerface_present is string else config.outerface_present) %}
{% if hostvars[inventory_hostname]["ansible_" + outerface]|d() %}
{% set _ = ferm__tpl_config.update({'outerface_present': [ outerface ] }) %}
{% endif %}
{% else %}
{% for outerface in config.outerface_present %}
{% if hostvars[inventory_hostname]["ansible_" + outerface]|d() %}
{% set _ = ferm__tpl_config.update({'outerface_present': [ outerface ] }) %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% elif config.outerfaces_present|d() %}
{% if config.outerfaces_present is string %}
{% if hostvars[inventory_hostname]["ansible_" + config.outerfaces_present]|d() %}
{% set _ = ferm__tpl_config.update({'outerface_present': [ config.outerfaces_present ] }) %}
{% for outerface in ([ config.outerfaces_present ] if config.outerfaces_present is string else config.outerfaces_present) %}
{% if hostvars[inventory_hostname]["ansible_" + outerface]|d() %}
{% set _ = ferm__tpl_config.update({'outerface_present': [ outerface ] }) %}
{% endif %}
{% else %}
{% for outerface in config.outerfaces_present %}
{% if hostvars[inventory_hostname]["ansible_" + outerface]|d() %}
{% set _ = ferm__tpl_config.update({'outerface_present': [ outerface ] }) %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% if config.protocol|d() %}
{% set _ = ferm__tpl_config.update({'protocol': ([ config.protocol ] if config.protocol is string else config.protocol) }) %}
Expand Down

0 comments on commit d178cbb

Please sign in to comment.