From ae6b1bfea752190f77ada97b9ffccbbf00a448d0 Mon Sep 17 00:00:00 2001 From: Avadhani Jonnavithula Date: Mon, 4 Jun 2018 09:53:06 -0700 Subject: [PATCH] Added support for IPv6 address and route configuration 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 --- .gitignore | 3 ++- filter_plugins/filters.py | 13 +++++++++++++ tasks/ethernet_configuration.yml | 22 ++++++++++++++++++++++ templates/ethernet_Debian.j2 | 31 +++++++++++++++++++++++++++++++ templates/ethernet_RedHat.j2 | 10 ++++++++++ templates/route6_RedHat.j2 | 18 ++++++++++++++++++ 6 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 templates/route6_RedHat.j2 diff --git a/.gitignore b/.gitignore index 29b636a..5c2ff30 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -*.iml \ No newline at end of file +*.iml +__pycache__ diff --git a/filter_plugins/filters.py b/filter_plugins/filters.py index 0d1f6b4..811a147 100644 --- a/filter_plugins/filters.py +++ b/filter_plugins/filters.py @@ -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"): diff --git a/tasks/ethernet_configuration.yml b/tasks/ethernet_configuration.yml index 8e10a63..dff895f 100644 --- a/tasks/ethernet_configuration.yml +++ b/tasks/ethernet_configuration.yml @@ -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 }}' @@ -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' @@ -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([]) }} diff --git a/templates/ethernet_Debian.j2 b/templates/ethernet_Debian.j2 index e2541d4..7554258 100644 --- a/templates/ethernet_Debian.j2 +++ b/templates/ethernet_Debian.j2 @@ -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 %} diff --git a/templates/ethernet_RedHat.j2 b/templates/ethernet_RedHat.j2 index 7d11066..e825355 100644 --- a/templates/ethernet_RedHat.j2 +++ b/templates/ethernet_RedHat.j2 @@ -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 %} diff --git a/templates/route6_RedHat.j2 b/templates/route6_RedHat.j2 new file mode 100644 index 0000000..b47e8c4 --- /dev/null +++ b/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 %} \ No newline at end of file