Skip to content
Snippets Groups Projects
Commit 7b8f43e4 authored by Attila Farkas's avatar Attila Farkas
Browse files

add new version of the interface role

parent 096cdd80
No related branches found
No related tags found
1 merge request!13Resolve "Integrate KYPO CRP interface Ansible role to Creator"
......@@ -2,39 +2,49 @@
interface_default_file: /etc/network/interfaces
interface_directory: '{{ interface_default_file }}.d'
interface_file_name:
interface_file: '
interface_file: >-
{%- if interface_file_name is defined and interface_file_name -%}
{{ interface_directory }}/{{ interface_file_name }}
{%- else -%}
{{ interface_default_file }}
{%- endif %}'
{%- endif -%}
interface_clean: True
interface_mtu: 1442
interface_ip:
interface_mac:
interface_name:
interface_identification:
interface_name: >-
{%- import "roles/common/templates/network.j2" as network with context -%}
{%- if interface_identification in ansible_interfaces -%}
{{ interface_identification }}
{%- elif interface_identification | ipv4 -%}
{{ network.ip_to_interface(interface_identification) }}
{%- elif interface_identification | regex_search("^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$")-%}
{{ network.mac_to_interface(interface_identification) }}
{%- else -%}
""
{%- endif -%}
interface_configuration_type: dhcp
interface_static_ip:
interface_static_netmask:
interface_mtu: 1442
interface_default_gateway:
interface_routes: []
# - gateway:
# network:
# mask:
# netmask:
interface_device: '
{%- import "roles/common/templates/network.j2" as network with context -%}
{%- if interface_ip is defined and interface_ip -%}
{{ network.ip_to_interface(interface_ip) | default("") }}
interface_sanity_check_msg: >-
{%- if not interface_identification -%}
interface_identification is not set,
{%- endif -%}
{%- if interface_configuration_type not in ["dhcp", "static"] -%}
unknown interface_configuration_type,
{%- endif -%}
{%- if interface_mac is defined and interface_mac -%}
{{ network.mac_to_interface(interface_mac) | default("") }}
{%- if interface_configuration_type == "static" and
(interface_static_ip is undefined or not interface_static_ip or
interface_static_netmask is undefined or not interface_static_netmask) -%}
interface_static_ip or interface_static_netmask is not defined
{%- endif -%}
{%- if interface_name is defined and interface_name -%}
{{ interface_name }}
{%- endif -%}'
interface_identifiers:
interface_ip: '{{ interface_ip }}'
interface_mac: '{{ interface_mac }}'
interface_name: '{{ interface_name }}'
interface_condition_single_interface_identifier: '{{ interface_identifiers | dict2items | map(attribute="value") | select("string") | select("ne", "") | list | length != 1 }}'
......@@ -8,7 +8,7 @@ galaxy_info:
author: Kamil Andoniadis
description: Basic network interface configuration
licence: MIT
min_ansible_version: 2.3.3
min_ansible_version: 2.8
platforms:
- name: Debian
versions:
......
......@@ -11,14 +11,14 @@
- name: remove old iface settings for retrieved interface name
replace:
path: '{{ item }}'
regexp: ^iface[ \t]{{ interface_device }}[ \t].*(\n[ \t]+.*)*
regexp: ^iface[ \t]{{ interface_name }}[ \t].*(\n[ \t]+.*)*
notify: interface_networking_restart
with_items: '{{ interface_config_files }}'
- name: remove the rest of old settings for retrieved interface name
replace:
path: '{{ item }}'
regexp: '^.*(?<=\s){{ interface_device }}(?=\s).*$'
regexp: '^.*(?<=\s){{ interface_name }}(?=\s).*$'
notify: interface_networking_restart
with_items: '{{ interface_config_files }}'
......
......@@ -3,22 +3,23 @@
blockinfile:
path: '{{ interface_file }}'
create: yes
marker: '# {mark} {{ interface_device }}'
marker: '# {mark} {{ interface_name }}'
block: |
allow-hotplug {{ interface_device }}
auto {{ interface_device }}
iface {{ interface_device }} inet static
address {{ interface_ip }}
netmask {{ interface_netmask }}
allow-hotplug {{ interface_name }}
auto {{ interface_name }}
iface {{ interface_name }} inet {{ interface_configuration_type }}
{% if interface_configuration_type == "static" -%}
address {{ interface_static_ip }}
netmask {{ interface_static_netmask }}
{% endif -%}
mtu {{ interface_mtu }}
{% if interface_default_gateway -%}
gateway {{ interface_default_gateway }}
up route add default gw {{ interface_default_gateway }}
up route add default gw {{ interface_default_gateway }}
{% endif -%}
{% if interface_routes -%}
{% for route in interface_routes -%}
post-up ip route add {{ route['network'] }}/{{ route['mask'] }} via {{ route['gateway'] }}
pre-down ip route del {{ route['network'] }}/{{ route['mask'] }} via {{ route['gateway'] }}
post-up ip route add {{ route['network'] }}/{{ route['netmask'] }} via {{ route['gateway'] }}
pre-down ip route del {{ route['network'] }}/{{ route['netmask'] }} via {{ route['gateway'] }}
{% endfor %}
{% endif %}
notify: interface_networking_restart
......
- name: check existence of single interface identifier
- name: sanity check
fail:
msg: there must be set exactly one of [interface_ip|interface_mac|interface_name] variables, got {{ interface_identifiers }}
when: interface_condition_single_interface_identifier
msg: '{{ interface_sanity_check_msg }}'
when: interface_sanity_check_msg | length > 0
- include: clean.yml
when: interface_clean is defined and interface_clean
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment