Skip to content

Commit

Permalink
Added support for IPv6 address and route configuration
Browse files Browse the repository at this point in the history
Changes:
1. New template file for route6 in rhel oses
2. Additional checks in filters
3. Additional lines in ethernet template files
4. Additional tasks for rhel oses
  • Loading branch information
Avadhani Jonnavithula committed Jun 4, 2018
1 parent 80eb1a1 commit ae6b1bf
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
.idea
*.iml
*.iml
__pycache__
13 changes: 13 additions & 0 deletions filter_plugins/filters.py
Expand Up @@ -97,6 +97,19 @@ def _interface_check(context, interface, interface_type=None):
elif fact_address:
return _fail("Interface %s has an IPv4 address but none was "
"requested" % device)

# Static IPv6 address
if interface.get("bootproto") == "static" and interface.get("ip6"):
fact_address = fact.get("ipv6", [])
# IP address
if len(fact_address) == 0:
return _fail("Interface %s has no IPv6 address" % device)

for item in fact_address:
if item["address"] == interface["ip6"]["address"] and item["prefix"] == str(interface["ip6"]["prefix"]):
break
else:
return _fail("Interface %s has incorrect IPv6 address" % device)

# MTU
if interface.get("mtu"):
Expand Down
22 changes: 22 additions & 0 deletions tasks/ethernet_configuration.yml
Expand Up @@ -32,6 +32,16 @@
notify:
- Bounce network devices

- name: RedHat | Write configuration files for rhel v6 route configuration
template:
src: 'route6_{{ ansible_os_family }}.j2'
dest: '{{ interfaces_net_path[ansible_os_family|lower] }}/route6-{{ item.device }}'
with_items: '{{ interfaces_ether_interfaces }}'
when: item.ip6 is defined and item.ip6.route is defined and ansible_os_family == 'RedHat'
register: ether_route6_add_result
notify:
- Bounce network devices

- name: RedHat | Remove configuration files for rhel route configuration
file:
path: '{{ interfaces_net_path[ansible_os_family|lower] }}/route-{{ item.device }}'
Expand All @@ -42,6 +52,16 @@
notify:
- Bounce network devices

- name: RedHat | Remove configuration files for rhel v6 route configuration
file:
path: '{{ interfaces_net_path[ansible_os_family|lower] }}/route6-{{ item.device }}'
state: absent
with_items: '{{ interfaces_ether_interfaces }}'
when: item.ip6 is not defined and ansible_os_family == 'RedHat'
register: ether_route6_del_result
notify:
- Bounce network devices

- name: RedHat | Write configuration files for rhel rule configuration
template:
src: 'rule_{{ ansible_os_family }}.j2'
Expand Down Expand Up @@ -70,6 +90,8 @@
ether_result.results | default([]) +
ether_route_add_result.results | default([]) +
ether_route_del_result.results | default([]) +
ether_route6_add_result.results | default([]) +
ether_route6_del_result.results | default([]) +
ether_rule_add_result.results | default([]) +
ether_rule_del_result.results | default([]) }}
Expand Down
31 changes: 31 additions & 0 deletions templates/ethernet_Debian.j2
Expand Up @@ -61,3 +61,34 @@ down ip rule del {{ rule }}
{% if item.device | match(vlan_interface_regex) %}
vlan-raw-device {{ item.device | regex_replace(vlan_interface_suffix_regex, '') }}
{% endif %}

{% if item.bootproto == 'static' %}
{% if item.ip6 is defined %}
iface {{ item.device }} inet6 static
address {{ item.ip6.address }}
{% if item.ip6.prefix is defined %}
netmask {{ item.ip6.prefix }}
{% endif %}
{% if item.ip6.gateway is defined %}
gateway {{ item.ip6.gateway }}
{% endif %}
{% endif %}
{% endif %}

{% if item.ip6 is defined %}
{% if item.ip6.route is defined %}
{% for i in item.ip6.route %}
{% set route = i.network %}
{% if 'gateway' in i %}
{% set route = route ~ ' via ' ~ i.gateway %}
{% else %}
{% set route = route ~ ' dev ' ~ item.device %}
{% endif %}
{% if 'table' in i %}
{% set route = route ~ ' table ' ~ i.table %}
{% endif %}
up ip route add {{ route }}
down ip route del {{ route }}
{% endfor %}
{% endif %}
{% endif %}
10 changes: 10 additions & 0 deletions templates/ethernet_RedHat.j2
Expand Up @@ -31,3 +31,13 @@ VLAN=yes
{% if item.mtu is defined %}
MTU={{ item.mtu }}
{% endif %}

{% if item.bootproto == 'static' %}
{% if item.ip6 is defined %}
IPV6INIT=yes
IPV6ADDR={{ item.ip6.address ~ '/' ~ item.ip6.prefix }}
{% if item.ip6.gateway is defined %}
IPV6_DEFAULTGW={{ item.ip6.gateway }}
{% endif %}
{% endif %}
{% endif %}
18 changes: 18 additions & 0 deletions templates/route6_RedHat.j2
@@ -0,0 +1,18 @@
# {{ansible_managed}}

{% if item.ip6 is defined %}
{% if item.ip6.route is defined %}
{% for i in item.ip6.route %}
{% set route = i.network %}
{% if 'gateway' in i %}
{% set route = route ~ ' via ' ~ i.gateway %}
{% else %}
{% set route = route ~ ' dev ' ~ item.device %}
{% endif %}
{% if 'table' in i %}
{% set route = route ~ ' table ' ~ i.table %}
{% endif %}
{{ route }}
{% endfor %}
{% endif %}
{% endif %}

0 comments on commit ae6b1bf

Please sign in to comment.