├── tests ├── inventory ├── test.yml └── interfaces.yml ├── .gitignore ├── templates ├── module.conf.j2 ├── interfaces.j2 ├── bond_slave_nmconnection.j2 ├── bond_slave_Debian.j2 ├── bridge_port_Debian.j2 ├── rule_RedHat.j2 ├── bond_slave_RedHat.j2 ├── route6_RedHat.j2 ├── bridge_port_nmconnection.j2 ├── bridge_port_RedHat.j2 ├── route_RedHat.j2 ├── bridge_RedHat.j2 ├── bond_RedHat.j2 ├── ethernet_RedHat.j2 ├── bridge_Debian.j2 ├── bond_Debian.j2 ├── ethernet_Debian.j2 ├── bridge_nmconnection.j2 ├── bond_nmconnection.j2 └── ethernet_nmconnection.j2 ├── vars ├── redhat-10.yml ├── redhat-9.yml ├── redhat-7.yml ├── redhat-8.yml ├── debian.yml └── main.yml ├── meta └── main.yml ├── .github └── workflows │ └── publish-role.yml ├── tasks ├── route_table_configuration.yml ├── service.yml ├── main.yml ├── debian.yml ├── redhat.yml ├── ethernet_configuration.yml ├── bridge_configuration.yml └── bond_configuration.yml ├── defaults └── main.yml ├── filter_plugins └── filters.py ├── handlers └── main.yml ├── README.md └── LICENSE /tests/inventory: -------------------------------------------------------------------------------- 1 | localhost 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | __pycache__ 4 | -------------------------------------------------------------------------------- /templates/module.conf.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | {{ module_name }} 4 | -------------------------------------------------------------------------------- /tests/test.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | roles: 3 | - { role: ../../ansible-role-interfaces, become: true } 4 | -------------------------------------------------------------------------------- /templates/interfaces.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | auto lo 4 | iface lo inet loopback 5 | 6 | source /etc/network/interfaces.d/* 7 | -------------------------------------------------------------------------------- /vars/redhat-10.yml: -------------------------------------------------------------------------------- 1 | --- 2 | interfaces_pkgs: 3 | - NetworkManager-config-server 4 | 5 | interfaces_net_path: /etc/NetworkManager/system-connections 6 | -------------------------------------------------------------------------------- /vars/redhat-9.yml: -------------------------------------------------------------------------------- 1 | --- 2 | interfaces_pkgs: 3 | - NetworkManager-config-server 4 | 5 | interfaces_net_path: /etc/NetworkManager/system-connections 6 | -------------------------------------------------------------------------------- /vars/redhat-7.yml: -------------------------------------------------------------------------------- 1 | --- 2 | interfaces_pkgs: 3 | - bridge-utils 4 | - iproute 5 | - iputils 6 | - libselinux-python 7 | 8 | interfaces_net_path: /etc/sysconfig/network-scripts 9 | -------------------------------------------------------------------------------- /vars/redhat-8.yml: -------------------------------------------------------------------------------- 1 | --- 2 | interfaces_pkgs: 3 | - dhcp-client 4 | - iproute 5 | - iputils 6 | - network-scripts 7 | 8 | interfaces_net_path: "{{ interfaces_use_nmconnection | ternary('/etc/NetworkManager/system-connections', '/etc/sysconfig/network-scripts') }}" 9 | -------------------------------------------------------------------------------- /vars/debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | interfaces_pkgs: 3 | - bridge-utils 4 | - ifenslave 5 | - ifupdown 6 | - iproute2 7 | - python{% if ansible_facts.python.version.major >= 3 %}3{% endif %}-selinux 8 | - resolvconf 9 | 10 | interfaces_net_path: /etc/network/interfaces.d 11 | -------------------------------------------------------------------------------- /templates/bond_slave_nmconnection.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [connection] 4 | id={{ item.1 }} 5 | type={{ (item.1 is match(dummy_interface_regex)) | ternary('dummy', 'ethernet') }} 6 | interface-name={{ item.1 }} 7 | 8 | master={{ item.0.device }} 9 | slave-type=bond 10 | -------------------------------------------------------------------------------- /templates/bond_slave_Debian.j2: -------------------------------------------------------------------------------- 1 | {% if not interfaces_merge %}# {{ ansible_managed }} 2 | {% else %}# Bond Slave - {{ item.0.device }}/{{ item.1 }} 3 | {% endif %} 4 | 5 | auto {{ item.1 }} 6 | iface {{ item.1 }} inet manual 7 | {% if ansible_facts.distribution_major_version | int < 11 %} 8 | bond-master {{ item.0.device }} 9 | {% endif %} 10 | -------------------------------------------------------------------------------- /templates/bridge_port_Debian.j2: -------------------------------------------------------------------------------- 1 | {% if not interfaces_merge %}# {{ ansible_managed }} 2 | {% else %}# Bridge Port - {{ item.0.device }}/{{ item.1 }} 3 | {% endif %} 4 | 5 | auto {{ item.1 }} 6 | iface {{ item.1 }} inet manual 7 | {% if item.1 is match(vlan_interface_regex) %} 8 | vlan-raw-device {{ item.1 | regex_replace(vlan_interface_suffix_regex, '') }} 9 | {% endif %} 10 | -------------------------------------------------------------------------------- /templates/rule_RedHat.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | {% for rule in item.rules %} 4 | {% if rule is mapping %} 5 | {% if rule.to is defined %} 6 | to {{ rule.to }} table {{ rule.table }} 7 | {% endif %} 8 | {% if rule.from is defined %} 9 | from {{ rule.from }} table {{ rule.table }} 10 | {% endif %} 11 | {% else %} 12 | {{ rule }} 13 | {% endif %} 14 | {% endfor %} 15 | -------------------------------------------------------------------------------- /vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Regular expression matching a VLAN interface of the form 3 | # '.'. 4 | vlan_interface_regex: '(?P.*)\.(?P\d{1,4})' 5 | 6 | # Regular expression matching the '.' suffix of a VLAN interface of 7 | # the form '.'. 8 | vlan_interface_suffix_regex: '\.\d{1,4}' 9 | 10 | # Regular expression matching a dummy interface base on name 11 | dummy_interface_regex: 'dummy.*' 12 | -------------------------------------------------------------------------------- /templates/bond_slave_RedHat.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | NAME={{ item.1 }} 4 | DEVICE={{ item.1 }} 5 | BOOTPROTO=none 6 | MASTER={{ item.0.device }} 7 | ONBOOT=yes 8 | SLAVE=yes 9 | USERCTL=no 10 | 11 | {% if item.0.ethtool_opts is defined %} 12 | ETHTOOL_OPTS="{{ item.0.ethtool_opts }}" 13 | {% endif %} 14 | 15 | {% if item.1 is match(vlan_interface_regex) %} 16 | VLAN=yes 17 | {% endif %} 18 | 19 | {% if ansible_facts.distribution_major_version | int >= 7 %} 20 | NM_CONTROLLED={{ interfaces_use_networkmanager | ternary('yes', 'no') }} 21 | {% endif %} 22 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Michaël Rigart 4 | role_name: interfaces 5 | description: An ansible role for configuring different network interfaces. 6 | company: Netronix.be 7 | license: GPLv3 8 | min_ansible_version: 2.2 9 | platforms: 10 | - name: Ubuntu 11 | versions: 12 | - all 13 | - name: Debian 14 | versions: 15 | - all 16 | - name: EL 17 | versions: 18 | - all 19 | - name: Fedora 20 | versions: 21 | - all 22 | galaxy_tags: 23 | - system 24 | dependencies: [] 25 | -------------------------------------------------------------------------------- /.github/workflows/publish-role.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Publish Ansible Role 3 | 'on': 4 | push: 5 | tags: 6 | - "v?[0-9]+.[0-9]+.[0-9]+" 7 | workflow_dispatch: 8 | jobs: 9 | galaxy: 10 | runs-on: ubuntu-latest 11 | name: Publish Ansible Role to Ansible Galaxy 12 | steps: 13 | # NOTE: The GitHub namespace is lower case, but the Galaxy namespace is upper case. 14 | # Hard code to the Galaxy namespace. 15 | - name: Publish Role 🚀 16 | run: ansible-galaxy import MichaelRigart $(basename ${{ github.repository }}) --api-key ${{ secrets.GALAXY_API_KEY }} --branch ${{ github.ref_name }} 17 | -------------------------------------------------------------------------------- /tasks/route_table_configuration.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ensure /etc/iproute2 directory exists 3 | become: true 4 | ansible.builtin.file: 5 | path: /etc/iproute2 6 | state: directory 7 | owner: root 8 | group: root 9 | mode: '0755' 10 | 11 | - name: Ensure IP routing tables are defined 12 | become: true 13 | blockinfile: 14 | create: true 15 | dest: /etc/iproute2/rt_tables 16 | owner: root 17 | group: root 18 | mode: '0644' 19 | block: | 20 | {% for table in interfaces_route_tables %} 21 | {{ table.id }} {{ table.name }} 22 | {% endfor %} 23 | when: interfaces_route_tables | length > 0 24 | -------------------------------------------------------------------------------- /templates/route6_RedHat.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | {% if item.ip6 is defined %} 4 | {% for i in item.ip6.route | default([]) %} 5 | {% set route = i.network %} 6 | {% if 'gateway' in i %} 7 | {% set route = route ~ ' via ' ~ i.gateway %} 8 | {% else %} 9 | {% set route = route ~ ' dev ' ~ item.device %} 10 | {% endif %} 11 | {% if 'table' in i %} 12 | {% set route = route ~ ' table ' ~ i.table %} 13 | {% endif %} 14 | {{ route -}} 15 | {% for option in i.options | default([]) %} 16 | {% if option is mapping %}{% set option = (option | dict2items | first).key %}{% endif %} 17 | {{ option -}} 18 | {% endfor %} 19 | 20 | {% endfor %} 21 | {% endif %} 22 | -------------------------------------------------------------------------------- /templates/bridge_port_nmconnection.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [connection] 4 | id={{ item.1 }} 5 | type={{ ('vlan' if item.1 is match(vlan_interface_regex) else 'dummy' if item.1 is match(dummy_interface_regex) else 'ethernet') }} 6 | interface-name={{ item.1 }} 7 | 8 | master={{ item.0.device }} 9 | slave-type=bridge 10 | 11 | {% if item.0.mtu is defined %} 12 | [ethernet] 13 | mtu={{ item.0.mtu }} 14 | {% endif %} 15 | 16 | {% if item.1 is match(vlan_interface_regex) %} 17 | [vlan] 18 | interface-name={{ item.1 }} 19 | parent={{ item.1 | regex_replace(vlan_interface_regex, '\g') }} 20 | id={{ item.1 | regex_replace(vlan_interface_regex, '\g') }} 21 | {% endif %} 22 | -------------------------------------------------------------------------------- /templates/bridge_port_RedHat.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | NAME={{ item.1 }} 4 | DEVICE={{ item.1 }} 5 | TYPE={{ (item.1 is match(vlan_interface_regex)) | ternary('Vlan', 'Ethernet') }} 6 | BOOTPROTO=none 7 | BRIDGE={{ item.0.device }} 8 | 9 | {% if item.0.ethtool_opts is defined %} 10 | ETHTOOL_OPTS="{{ item.0.ethtool_opts }}" 11 | {% endif %} 12 | 13 | {% if item.0.onboot is defined %} 14 | ONBOOT={{ item.0.onboot }} 15 | {% endif %} 16 | 17 | {% if ansible_facts.distribution_major_version | int >= 7 %} 18 | NM_CONTROLLED={{ interfaces_use_networkmanager | ternary('yes', 'no') }} 19 | {% endif %} 20 | 21 | {% if item.1 is match(vlan_interface_regex) %} 22 | VLAN=yes 23 | {% endif %} 24 | 25 | {% if item.0.mtu is defined %} 26 | MTU={{ item.0.mtu }} 27 | {% endif %} 28 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | interfaces_use_networkmanager: "{{ ansible_facts.os_family == 'RedHat' and ansible_facts.distribution_major_version | int >= 9 }}" 3 | interfaces_use_nmconnection: "{{ ansible_facts.os_family == 'RedHat' and ansible_facts.distribution_major_version | int >= 9 }}" 4 | 5 | interfaces_pkg_state: present 6 | interfaces_route_tables: [] 7 | interfaces_ether_interfaces: [] 8 | interfaces_bridge_interfaces: [] 9 | interfaces_bond_interfaces: [] 10 | interfaces_workaround_centos_remove: 11 | - ens3 12 | - ens3-1 13 | - eth0 14 | interfaces_pause_time: 0 15 | interfaces_setup_filter: "{{ omit }}" 16 | interfaces_setup_gather_subset: "{{ omit }}" 17 | interfaces_bond_setup_slaves: true 18 | interfaces_merge: false 19 | interfaces_bounce_ignore_errors: false 20 | -------------------------------------------------------------------------------- /tasks/service.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # NOTE: start the network service after configuring interfaces. This may result 3 | # in some interfaces being bounced again in handlers, but avoids issues where 4 | # the initial network configuration is invalid, preventing the service from 5 | # starting. 6 | 7 | - name: RedHat | ensure network service is started and enabled 8 | become: true 9 | service: 10 | name: network 11 | enabled: true 12 | state: started 13 | when: 14 | - ansible_facts.os_family == 'RedHat' 15 | - not interfaces_use_networkmanager 16 | 17 | - name: RedHat | ensure NetworkManager service is started and enabled 18 | become: true 19 | service: 20 | name: NetworkManager 21 | enabled: true 22 | state: started 23 | when: 24 | - ansible_facts.os_family == 'RedHat' 25 | - interfaces_use_networkmanager 26 | -------------------------------------------------------------------------------- /templates/route_RedHat.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | {% for i in item.route | default([]) %} 4 | {# Workaround for Ansible bug https://github.com/ansible/ansible/issues/17872. #} 5 | {% if i is mapping %}{# If route is not a mapping, then assume it's a complete rule #} 6 | {% set prefix = ('0.0.0.0/' ~ i.netmask) | ansible.utils.ipaddr('prefix') %} 7 | {% set route = i.network ~ '/' ~ prefix %} 8 | {% if 'gateway' in i %} 9 | {% set route = route ~ ' via ' ~ i.gateway %} 10 | {% else %} 11 | {% set route = route ~ ' dev ' ~ item.device %} 12 | {% endif %} 13 | {% if 'table' in i %} 14 | {% set route = route ~ ' table ' ~ i.table %} 15 | {% endif %} 16 | {{ route -}} 17 | {% for option in i.options | default([]) %} 18 | {% if option is mapping %}{% set option = (option | dict2items | first).key %}{% endif %} 19 | {{ option -}} 20 | {% endfor %} 21 | 22 | {% else %} 23 | {% set route = i %} 24 | {{ route }} 25 | {% endif %} 26 | {% endfor %} 27 | -------------------------------------------------------------------------------- /templates/bridge_RedHat.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | NAME={{ item.device }} 4 | DEVICE={{ item.device }} 5 | TYPE=Bridge 6 | {% if item.hwaddr is defined %} 7 | HWADDR={{ item.hwaddr }} 8 | {% endif %} 9 | {% if item.bootproto == 'static' %} 10 | BOOTPROTO=none 11 | {% if item.address is defined %} 12 | IPADDR={{ item.address }} 13 | {% endif %} 14 | {% if item.netmask is defined %} 15 | NETMASK={{ item.netmask }} 16 | {% endif %} 17 | {% if item.gateway is defined %} 18 | GATEWAY={{ item.gateway }} 19 | {% endif %} 20 | {% endif %} 21 | {% if item.bootproto == 'dhcp' %} 22 | BOOTPROTO=dhcp 23 | {% endif %} 24 | {% if item.stp is defined %} 25 | STP={{ item.stp }} 26 | {% endif %} 27 | {% if item.defroute is defined %} 28 | DEFROUTE={{ item.defroute | bool | ternary('yes', 'no') }} 29 | {% endif %} 30 | {% if item.onboot is defined %} 31 | ONBOOT={{ item.onboot | bool | ternary('yes', 'no') }} 32 | {% endif %} 33 | {% if ansible_facts.distribution_major_version | int >= 7 %} 34 | NM_CONTROLLED={{ interfaces_use_networkmanager | ternary('yes', 'no') }} 35 | {% endif %} 36 | {% if item.mtu is defined %} 37 | MTU={{ item.mtu }} 38 | {% endif %} 39 | {% if item.zone is defined %} 40 | ZONE="{{ item.zone }}" 41 | {% endif %} 42 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Gather variables for each operating system 3 | include_vars: "{{ lookup('first_found', params) }}" 4 | vars: 5 | params: 6 | files: 7 | - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml" 8 | - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml" 9 | - "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml" 10 | - "{{ ansible_facts['distribution'] | lower }}.yml" 11 | - "{{ ansible_facts['os_family'] | lower }}.yml" 12 | paths: 13 | - "{{ role_path }}/vars" 14 | 15 | - include_tasks: "{{ ansible_facts.os_family | lower }}.yml" 16 | 17 | - import_tasks: 'route_table_configuration.yml' 18 | tags: configuration 19 | 20 | - import_tasks: 'bond_configuration.yml' 21 | when: interfaces_bond_interfaces is defined 22 | tags: configuration 23 | 24 | - import_tasks: 'bridge_configuration.yml' 25 | when: interfaces_bridge_interfaces is defined 26 | tags: configuration 27 | 28 | - import_tasks: 'ethernet_configuration.yml' 29 | when: interfaces_ether_interfaces is defined 30 | tags: configuration 31 | 32 | - name: Debian | Merge configuration in interface file 33 | assemble: 34 | src: "{{ interfaces_net_path['debian'] }}" 35 | dest: /etc/network/interfaces 36 | tags: configuration 37 | when: 38 | - ansible_facts.os_family | lower == 'debian' 39 | - interfaces_merge 40 | 41 | - import_tasks: 'service.yml' 42 | tags: service 43 | -------------------------------------------------------------------------------- /tasks/debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Debian | install current/latest network packages versions 3 | apt: 4 | pkg: '{{ interfaces_pkgs }}' 5 | state: '{{ interfaces_pkg_state }}' 6 | update_cache: yes 7 | cache_valid_time: 3600 8 | tags: package 9 | become: true 10 | 11 | - name: Debian | install VLAN packages 12 | become: true 13 | apt: 14 | pkg: vlan 15 | state: '{{ interfaces_pkg_state }}' 16 | update_cache: yes 17 | cache_valid_time: 3600 18 | when: > 19 | all_interfaces | 20 | selectattr('device', 'match', vlan_interface_regex) | 21 | list | 22 | length > 0 23 | vars: 24 | all_interfaces: > 25 | {{ interfaces_ether_interfaces + 26 | interfaces_bridge_interfaces + 27 | interfaces_bond_interfaces }} 28 | notify: 29 | - Check whether /etc/modules-load.d exists 30 | - Make sure the 8021q module is loaded 31 | - Make sure the 8021q module is loaded at boot via /etc/modules-load.d 32 | - Make sure the 8021q module is loaded at boot via /etc/modules 33 | tags: package 34 | 35 | - name: Debian | Copy new interfaces file to source interfaces.d 36 | become: true 37 | template: 38 | src: interfaces.j2 39 | dest: /etc/network/interfaces 40 | owner: root 41 | group: root 42 | mode: 0644 43 | tags: configuration 44 | when: not interfaces_merge 45 | 46 | - name: Debian | Create the directory for interface cfg files 47 | become: true 48 | file: 49 | path: '{{ interfaces_net_path }}' 50 | state: directory 51 | tags: configuration 52 | 53 | - name: Debian | Ensure lo single configuration file 54 | copy: 55 | dest: /etc/network/interfaces.d/ifcfg-lo 56 | mode: 0644 57 | content: | 58 | # Loopback 59 | 60 | auto lo 61 | iface lo inet loopback 62 | when: interfaces_merge 63 | -------------------------------------------------------------------------------- /templates/bond_RedHat.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | NAME={{ item.device }} 4 | DEVICE={{ item.device }} 5 | TYPE=Bond 6 | {% if item.hwaddr is defined %} 7 | HWADDR={{ item.hwaddr }} 8 | {% endif %} 9 | USERCTL=no 10 | {% if item.bootproto == 'static' %} 11 | BOOTPROTO=none 12 | {% if item.address is defined %} 13 | IPADDR={{ item.address }} 14 | {% endif %} 15 | {% if item.netmask is defined %} 16 | NETMASK={{ item.netmask }} 17 | {% endif %} 18 | {% if item.gateway is defined %} 19 | GATEWAY={{ item.gateway }} 20 | {% endif %} 21 | {% endif %} 22 | {% if item.bootproto == 'dhcp' %} 23 | BOOTPROTO=dhcp 24 | {% endif %} 25 | {% if item.defroute is defined %} 26 | DEFROUTE={{ item.defroute | bool | ternary('yes', 'no') }} 27 | {% endif %} 28 | {% if item.onboot is defined %} 29 | ONBOOT={{ item.onboot | bool | ternary('yes', 'no') }} 30 | {% endif %} 31 | BONDING_OPTS="{% if item.bond_mode is defined %}mode={{ item.bond_mode }} {% endif %}{% if item.bond_ad_select is defined %}ad_select={{ item.bond_ad_select }} {% endif %}{% if item.bond_updelay is defined %}updelay={{ item.bond_updelay }} {% endif %}{% if item.bond_downdelay is defined %}downdelay={{ item.bond_downdelay }} {% endif %}{% if item.bond_xmit_hash_policy is defined %}xmit_hash_policy={{ item.bond_xmit_hash_policy }} {% endif %}{% if item.bond_lacp_rate is defined %}lacp_rate={{ item.bond_lacp_rate }} {% endif %}{% if item.bond_primary is defined %}primary={{ item.bond_primary }} {% endif %}miimon={{ item.bond_miimon|default(100) }}" 32 | {% if ansible_facts.distribution_major_version | int >= 7 %} 33 | NM_CONTROLLED={{ interfaces_use_networkmanager | ternary('yes', 'no') }} 34 | {% endif %} 35 | {% if item.mtu is defined %} 36 | MTU={{ item.mtu }} 37 | {% endif %} 38 | {% if item.zone is defined %} 39 | ZONE="{{ item.zone }}" 40 | {% endif %} 41 | {% for bridge in interfaces_bridge_interfaces %} 42 | {% if item.device in bridge.ports %} 43 | BRIDGE={{ bridge.device }} 44 | {% endif %} 45 | {% endfor %} 46 | -------------------------------------------------------------------------------- /templates/ethernet_RedHat.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | NAME={{ item.device }} 4 | DEVICE={{ item.device }} 5 | TYPE={{ (item.device is match(vlan_interface_regex)) | ternary('Vlan', 'Ethernet') }} 6 | {% if item.hwaddr is defined %} 7 | HWADDR={{ item.hwaddr }} 8 | {% endif %} 9 | {% if item.bootproto == 'static' %} 10 | BOOTPROTO=none 11 | {% if item.address is defined %} 12 | IPADDR={{ item.address }} 13 | {% endif %} 14 | {% if item.netmask is defined %} 15 | NETMASK={{ item.netmask }} 16 | {% endif %} 17 | {% if item.gateway is defined %} 18 | GATEWAY={{ item.gateway }} 19 | {% endif %} 20 | {% if item.dnsnameservers is defined %} 21 | {% for dns_server in item.dnsnameservers.split(' ')[:2] %} 22 | DNS{{ loop.index }}={{ dns_server }} 23 | {% endfor %} 24 | {% endif %} 25 | {% if item.dnssearch is defined %} 26 | DOMAIN={{ item.dnssearch }} 27 | {% endif %} 28 | {% endif %} 29 | {% if item.bootproto == 'dhcp' %} 30 | BOOTPROTO=dhcp 31 | {% endif %} 32 | {% if item.defroute is defined %} 33 | DEFROUTE={{ item.defroute | bool | ternary('yes', 'no') }} 34 | {% endif %} 35 | {% if item.ethtool_opts is defined %} 36 | ETHTOOL_OPTS="{{ item.ethtool_opts }}" 37 | {% endif %} 38 | {% if item.onboot is defined %} 39 | ONBOOT={{ item.onboot | bool | ternary('yes', 'no') }} 40 | {% endif %} 41 | {% if ansible_facts.distribution_major_version | int >= 7 %} 42 | NM_CONTROLLED={{ interfaces_use_networkmanager | ternary('yes', 'no') }} 43 | {% endif %} 44 | {% if item.device is match(vlan_interface_regex) %} 45 | VLAN=yes 46 | {% endif %} 47 | {% if item.ingress_priority_map is defined %} 48 | VLAN_INGRESS_PRIORITY_MAP={{ item.ingress_priority_map }} 49 | {% endif %} 50 | {% if item.egress_priority_map is defined %} 51 | VLAN_EGRESS_PRIORITY_MAP={{ item.egress_priority_map }} 52 | {% endif %} 53 | {% if item.mtu is defined %} 54 | MTU={{ item.mtu }} 55 | {% endif %} 56 | {% if item.zone is defined %} 57 | ZONE="{{ item.zone }}" 58 | {% endif %} 59 | {% if item.bootproto == 'static' %} 60 | {% if item.ip6 is defined %} 61 | IPV6INIT=yes 62 | IPV6ADDR={{ item.ip6.address ~ '/' ~ item.ip6.prefix }} 63 | {% if item.ip6.gateway is defined %} 64 | IPV6_DEFAULTGW={{ item.ip6.gateway }} 65 | {% endif %} 66 | {% if item.ip6.defaultdev is defined %} 67 | IPV6_DEFAULTDEV={{ item.ip6.defaultdev }} 68 | {% endif %} 69 | {% endif %} 70 | {% endif %} 71 | -------------------------------------------------------------------------------- /tests/interfaces.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | become: True 4 | vars: 5 | veth1_name: veth1 6 | veth1_peer: veth3 7 | veth2_name: veth2 8 | veth2_peer: veth4 9 | bond_name: bond7 10 | bridge_name: br42 11 | pre_tasks: 12 | - name: Ensure veth1 exists 13 | command: ip l add name {{ veth1_name }} type veth peer name {{ veth1_peer }} 14 | args: 15 | creates: "/sys/class/net/{{ veth1_name }}" 16 | - name: Ensure veth1 is up 17 | command: ip l set {{ veth1_name }} up 18 | - name: Ensure veth1 peer is up 19 | command: ip l set {{ veth1_peer }} up 20 | 21 | - name: Ensure veth2 exists 22 | command: ip l add name {{ veth2_name }} type veth peer name {{ veth2_peer }} 23 | args: 24 | creates: "/sys/class/net/{{ veth2_name }}" 25 | - name: Ensure veth2 is up 26 | command: ip l set {{ veth2_name }} up 27 | - name: Ensure veth2 peer is up 28 | command: ip l set {{ veth2_peer }} up 29 | roles: 30 | - role: MichaelRigart.interfaces 31 | interfaces_route_tables: 32 | - id: 42 33 | name: myroutetable 34 | interfaces_ether_interfaces: 35 | - device: "{{ veth1_name }}.1001" 36 | bootproto: static 37 | address: 10.1.0.1 38 | netmask: 255.255.255.0 39 | rules: 40 | - from 10.1.0.0/24 table myroutetable 41 | - to 10.1.0.0/24 table myroutetable 42 | route: 43 | - network: 10.6.0.0 44 | netmask: 255.255.255.0 45 | gateway: 10.1.0.2 46 | - network: 10.3.0.0 47 | netmask: 255.255.255.0 48 | gateway: 10.1.0.3 49 | table: myroutetable 50 | - network: 10.1.0.0 51 | netmask: 255.255.255.0 52 | table: myroutetable 53 | - network: 10.7.0.0 54 | netmask: 255.255.255.0 55 | gateway: 10.1.0.2 56 | options: 57 | - onlink 58 | - device: "{{ bridge_name }}.1002" 59 | bootproto: static 60 | address: 10.2.0.1 61 | netmask: 255.255.255.0 62 | - device: "{{ bond_name }}.1003" 63 | bootproto: static 64 | address: 10.3.0.1 65 | netmask: 255.255.255.0 66 | interfaces_bond_interfaces: 67 | - device: "{{ bond_name }}" 68 | bootproto: static 69 | address: 10.4.0.1 70 | netmask: 255.255.255.0 71 | bond_mode: 802.3ad 72 | bond_slaves: 73 | - "{{ veth1_name }}" 74 | - "{{ veth2_name }}" 75 | interfaces_bridge_interfaces: 76 | - device: "{{ bridge_name }}" 77 | bootproto: static 78 | address: 10.5.0.1 79 | netmask: 255.255.255.0 80 | ports: 81 | - "{{ bond_name }}.1005" 82 | -------------------------------------------------------------------------------- /templates/bridge_Debian.j2: -------------------------------------------------------------------------------- 1 | {% if not interfaces_merge %}# {{ ansible_managed }} 2 | {% else %}# Bridge - {{ item.device }} 3 | {% endif %} 4 | 5 | auto {{ item.device }} 6 | {% if item.bootproto == 'manual' %} 7 | iface {{ item.device }} inet manual 8 | {% endif %} 9 | {% if item.bootproto == 'dhcp' %} 10 | iface {{ item.device }} inet dhcp 11 | {% endif %} 12 | {% if item.bootproto == 'static' %} 13 | iface {{ item.device }} inet static 14 | {% if item.address is defined %} 15 | address {{ item.address }} 16 | {% endif %} 17 | {% if item.netmask is defined %} 18 | netmask {{ item.netmask }} 19 | {% endif %} 20 | {% if item.gateway is defined %} 21 | gateway {{ item.gateway }} 22 | {% endif %} 23 | {% endif %} 24 | {% if item.mtu is defined %} 25 | mtu {{ item.mtu }} 26 | {% endif %} 27 | {% if item.hwaddr is defined %} 28 | hwaddress {{ item.hwaddr }} 29 | {% endif %} 30 | {% if item.pre_up is defined %} 31 | pre-up {{ item.pre_up }} 32 | {% endif %} 33 | {% if item.ports is defined %} 34 | bridge_ports {{ item.ports|join(' ') }}{% if item.ports | default([], true) | length == 0 %}none{% endif %} 35 | 36 | {% endif %} 37 | {% if item.stp is defined %} 38 | bridge_stp {{ item.stp }} 39 | {% endif %} 40 | {% if item.fd is defined %} 41 | bridge_fd {{ item.fd }} 42 | {% endif %} 43 | {% if item.vlan_aware is defined %} 44 | bridge-vlan-aware {{ item.vlan_aware }} 45 | {% endif %} 46 | 47 | {% if item.route is defined %} 48 | {% for i in item.route %} 49 | {# Workaround for Ansible bug https://github.com/ansible/ansible/issues/17872. #} 50 | {% if i is mapping %} {# If route is not a mapping, then assume it's a complete rule #} 51 | {% set prefix = ('0.0.0.0/' ~ i.netmask) | ansible.utils.ipaddr('prefix') %} 52 | {% set route = i.network ~ '/' ~ prefix %} 53 | {% if 'gateway' in i %} 54 | {% set route = route ~ ' via ' ~ i.gateway %} 55 | {% else %} 56 | {% set route = route ~ ' dev ' ~ item.device %} 57 | {% endif %} 58 | {% if 'table' in i %} 59 | {% set route = route ~ ' table ' ~ i.table %} 60 | {% endif %} 61 | {% for option in i.options | default([]) %} 62 | {% if option is mapping %} 63 | {% set option = (option | dict2items | first).key %} 64 | {% endif %} 65 | {% set route = route ~ ' ' ~ option %} 66 | {% endfor %} 67 | {% else %} 68 | {% set route = i %} 69 | {% endif %} 70 | up ip route add {{ route }} 71 | down ip route del {{ route }} 72 | {% endfor %} 73 | 74 | {% endif %} 75 | {% if item.rules is defined %} 76 | {% for rule in item.rules %} 77 | {% if rule is mapping %} 78 | {% if rule.to is defined %} 79 | {% set rule_str = 'to ' ~ rule.to %} 80 | {% endif %} 81 | {% if rule.from is defined %} 82 | {% set rule_str = 'from ' ~ rule.from %} 83 | {% endif %} 84 | {% if rule.table is defined %} 85 | {% set rule_str = rule_str ~ ' table' ~ rule.table %} 86 | {% endif %} 87 | {% else %} 88 | {% set rule_str = rule %} 89 | {% endif %} 90 | up ip rule add {{ rule_str }} 91 | down ip rule del {{ rule_str }} 92 | {% endfor %} 93 | {% endif %} 94 | -------------------------------------------------------------------------------- /templates/bond_Debian.j2: -------------------------------------------------------------------------------- 1 | {% if not interfaces_merge %}# {{ ansible_managed }} 2 | {% else %}# Bond - {{ item.device }} 3 | {% endif %} 4 | 5 | auto {{ item.device }} 6 | {% if item.bootproto == 'manual' %} 7 | iface {{ item.device }} inet manual 8 | {% endif %} 9 | {% if item.bootproto == 'dhcp' %} 10 | iface {{ item.device }} inet dhcp 11 | {% endif %} 12 | {% if item.bootproto == 'static' %} 13 | iface {{ item.device }} inet static 14 | {% if item.address is defined %} 15 | address {{ item.address }} 16 | {% endif %} 17 | {% if item.netmask is defined %} 18 | netmask {{ item.netmask }} 19 | {% endif %} 20 | {% if item.gateway is defined %} 21 | gateway {{ item.gateway }} 22 | {% endif %} 23 | {% endif %} 24 | {% if item.mtu is defined %} 25 | mtu {{ item.mtu }} 26 | {% endif %} 27 | {% if item.hwaddr is defined %} 28 | hwaddress {{ item.hwaddr }} 29 | {% endif %} 30 | {% if item.pre_up is defined %} 31 | pre-up {{ item.pre_up }} 32 | {% endif %} 33 | {% if item.bond_mode is defined %} 34 | bond-mode {{ item.bond_mode }} 35 | {% endif %} 36 | {% if item.bond_ad_select is defined %} 37 | bond-ad_select {{ item.bond_ad_select }} 38 | {% endif %} 39 | bond-miimon {{ item.bond_miimon|default(100) }} 40 | {% if item.bond_lacp_rate is defined %} 41 | bond-lacp-rate {{ item.bond_lacp_rate }} 42 | {% endif %} 43 | {% if item.bond_min_links is defined %} 44 | bond-min-links {{ item.bond_min_links }} 45 | {% endif %} 46 | {% if item.bond_downdelay is defined %} 47 | bond-downdelay {{ item.bond_downdelay }} 48 | {% endif %} 49 | {% if item.bond_updelay is defined %} 50 | bond-updelay {{ item.bond_updelay }} 51 | {% endif %} 52 | {% if item.bond_xmit_hash_policy is defined %} 53 | bond-xmit-hash-policy {{ item.bond_xmit_hash_policy }} 54 | {% endif %} 55 | {% if item.bond_primary is defined %} 56 | bond-primary {{ item.bond_primary }} 57 | {% endif %} 58 | {% if item.bond_slaves is defined and item.bond_mode | default == 'active-backup' %} 59 | bond-slaves none 60 | {% endif %} 61 | {% if item.bond_slaves is defined and item.bond_mode | default == '802.3ad' %} 62 | bond-slaves {{ item.bond_slaves|join(' ') }} 63 | {% endif %} 64 | 65 | {% if item.route is defined %} 66 | {% for i in item.route %} 67 | {# Workaround for Ansible bug https://github.com/ansible/ansible/issues/17872. #} 68 | {% if i is mapping %} {# If route is not a mapping, then assume it's a complete rule #} 69 | {% set prefix = ('0.0.0.0/' ~ i.netmask) | ansible.utils.ipaddr('prefix') %} 70 | {% set route = i.network ~ '/' ~ prefix %} 71 | {% if 'gateway' in i %} 72 | {% set route = route ~ ' via ' ~ i.gateway %} 73 | {% else %} 74 | {% set route = route ~ ' dev ' ~ item.device %} 75 | {% endif %} 76 | {% if 'table' in i %} 77 | {% set route = route ~ ' table ' ~ i.table %} 78 | {% endif %} 79 | {% for option in i.options | default([]) %} 80 | {% if option is mapping %} 81 | {% set option = (option | dict2items | first).key %} 82 | {% endif %} 83 | {% set route = route ~ ' ' ~ option %} 84 | {% endfor %} 85 | {% else %} 86 | {% set route = i %} 87 | {% endif %} 88 | up ip route add {{ route }} 89 | down ip route del {{ route }} 90 | {% endfor %} 91 | 92 | {% endif %} 93 | {% if item.rules is defined %} 94 | {% for rule in item.rules %} 95 | {% if rule is mapping %} 96 | {% if rule.to is defined %} 97 | {% set rule_str = 'to ' ~ rule.to %} 98 | {% endif %} 99 | {% if rule.from is defined %} 100 | {% set rule_str = 'from ' ~ rule.from %} 101 | {% endif %} 102 | {% if rule.table is defined %} 103 | {% set rule_str = rule_str ~ ' table' ~ rule.table %} 104 | {% endif %} 105 | {% else %} 106 | {% set rule_str = rule %} 107 | {% endif %} 108 | up ip rule add {{ rule_str }} 109 | down ip rule del {{ rule_str }} 110 | {% endfor %} 111 | {% endif %} 112 | -------------------------------------------------------------------------------- /templates/ethernet_Debian.j2: -------------------------------------------------------------------------------- 1 | {% if not interfaces_merge %}# {{ ansible_managed }} 2 | {% else %}# Ethernet - {{ item.device }} 3 | {% endif %} 4 | 5 | {{ item.allowclass | default('auto') }} {{ item.device }} 6 | {% if item.bootproto == 'manual' %} 7 | iface {{ item.device }} inet manual 8 | {% endif %} 9 | {% if item.bootproto == 'dhcp' %} 10 | iface {{ item.device }} inet dhcp 11 | {% endif %} 12 | {% if item.bootproto == 'static' %} 13 | iface {{ item.device }} inet static 14 | {% if item.address is defined %} 15 | address {{ item.address }} 16 | {% endif %} 17 | {% if item.netmask is defined %} 18 | netmask {{ item.netmask }} 19 | {% endif %} 20 | {% if item.gateway is defined %} 21 | gateway {{ item.gateway }} 22 | {% endif %} 23 | {% if item.dnsnameservers is defined %} 24 | dns-nameservers {{ item.dnsnameservers }} 25 | {% endif %} 26 | {% endif %} 27 | {% if item.mtu is defined %} 28 | mtu {{ item.mtu }} 29 | {% endif %} 30 | {% if item.hwaddr is defined %} 31 | hwaddress ether {{ item.hwaddr }} 32 | {% endif %} 33 | {% if item.pre_up is defined %} 34 | pre-up {{ item.pre_up }} 35 | {% endif %} 36 | {% if item.dnssearch is defined %} 37 | dns-search {{ item.dnssearch }} 38 | {% endif %} 39 | {% if item.wpaconf is defined %} 40 | wpa-conf {{ item.wpaconf }} 41 | {% endif %} 42 | 43 | {% if item.route is defined %} 44 | {% for i in item.route %} 45 | {# Workaround for Ansible bug https://github.com/ansible/ansible/issues/17872. #} 46 | {% if i is mapping %} {# If route is not a mapping, then assume it's a complete rule #} 47 | {% set prefix = ('0.0.0.0/' ~ i.netmask) | ansible.utils.ipaddr('prefix') %} 48 | {% set route = i.network ~ '/' ~ prefix %} 49 | {% if 'gateway' in i %} 50 | {% set route = route ~ ' via ' ~ i.gateway %} 51 | {% else %} 52 | {% set route = route ~ ' dev ' ~ item.device %} 53 | {% endif %} 54 | {% if 'table' in i %} 55 | {% set route = route ~ ' table ' ~ i.table %} 56 | {% endif %} 57 | {% for option in i.options | default([]) %} 58 | {% if option is mapping %} 59 | {% set option = (option | dict2items | first).key %} 60 | {% endif %} 61 | {% set route = route ~ ' ' ~ option %} 62 | {% endfor %} 63 | {% else %} 64 | {% set route = i %} 65 | {% endif %} 66 | up ip route add {{ route }} 67 | down ip route del {{ route }} 68 | {% endfor %} 69 | 70 | {% endif %} 71 | {% if item.rules is defined %} 72 | {% for rule in item.rules %} 73 | {% if rule is mapping %} 74 | {% if rule.to is defined %} 75 | {% set rule_str = 'to ' ~ rule.to %} 76 | {% endif %} 77 | {% if rule.from is defined %} 78 | {% set rule_str = 'from ' ~ rule.from %} 79 | {% endif %} 80 | {% if rule.table is defined %} 81 | {% set rule_str = rule_str ~ ' table' ~ rule.table %} 82 | {% endif %} 83 | {% else %} 84 | {% set rule_str = rule %} 85 | {% endif %} 86 | up ip rule add {{ rule_str }} 87 | down ip rule del {{ rule_str }} 88 | {% endfor %} 89 | {% endif %} 90 | 91 | {% if item.device is match(vlan_interface_regex) %} 92 | 93 | vlan-raw-device {{ item.device | regex_replace(vlan_interface_suffix_regex, '') }} 94 | {% endif %} 95 | {% if item.bootproto == 'static' %} 96 | 97 | {% if item.ip6 is defined %} 98 | iface {{ item.device }} inet6 static 99 | address {{ item.ip6.address }} 100 | {% if item.ip6.prefix is defined %} 101 | netmask {{ item.ip6.prefix }} 102 | {% endif %} 103 | {% if item.ip6.gateway is defined %} 104 | gateway {{ item.ip6.gateway }} 105 | {% endif %} 106 | {% endif %} 107 | {% endif %} 108 | {% if item.ip6 is defined %} 109 | 110 | {% for i in item.ip6.route | default([]) %} 111 | {% set route = i.network %} 112 | {% if 'gateway' in i %} 113 | {% set route = route ~ ' via ' ~ i.gateway %} 114 | {% else %} 115 | {% set route = route ~ ' dev ' ~ item.device %} 116 | {% endif %} 117 | {% if 'table' in i %} 118 | {% set route = route ~ ' table ' ~ i.table %} 119 | {% endif %} 120 | {% for option in i.options | default([]) %} 121 | {% if option is mapping %} 122 | {% set option = (option | dict2items | first).key %} 123 | {% endif %} 124 | {% set route = route ~ ' ' ~ option %} 125 | {% endfor %} 126 | up ip -6 route add {{ route }} 127 | down ip -6 route del {{ route }} 128 | {% endfor %} 129 | {% endif %} 130 | -------------------------------------------------------------------------------- /templates/bridge_nmconnection.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [connection] 4 | id={{ item.device }} 5 | type=bridge 6 | interface-name={{ item.device }} 7 | {% if item.zone is defined %} 8 | zone={{ item.zone }} 9 | {% endif %} 10 | 11 | {% if item.mtu is defined %} 12 | [ethernet] 13 | mtu={{ item.mtu }} 14 | {% endif %} 15 | 16 | [bridge] 17 | interface-name={{ item.device }} 18 | {% if item.stp is defined %} 19 | stp={{ item.stp }} 20 | {% endif %} 21 | 22 | [ipv4] 23 | {% if item.bootproto == 'dhcp' %} 24 | method=auto 25 | {% elif item.bootproto == 'static' and item.address is defined and item.address | length %} 26 | method=manual 27 | {% if item.netmask is defined %} 28 | address1={{ (item.address ~'/'~ item.netmask) | ansible.utils.ipaddr('host/prefix') }} 29 | {% endif %} 30 | {% if item.gateway is defined and item.gateway | length %} 31 | gateway={{ item.gateway }} 32 | {% endif %} 33 | {% else %} 34 | method=disabled 35 | {% endif %} 36 | {% for route in item.route | default([]) %} 37 | {% set route_options = [] %} 38 | {# Ignoring dev option - needed in Network Scripts #} 39 | {# as it is not needed in Network Manager #} 40 | {% for option in route.options | default([]) | reject('match', '^dev ') %} 41 | {% if option is mapping %} 42 | {# We're gonna assume it's a mapping of one key with value, and #} 43 | {# since dict2items returns an array, we're selecting the first item #} 44 | {% set option = option | dict2items | first %} 45 | {% set _ = route_options.append(option.key ~ '=' ~ option.value) %} 46 | {% elif option in ['onlink', 'lock-window', 'lock-cwdn', 'lock-mtu'] %} 47 | {% set _ = route_options.append(option ~ '=true') %} 48 | {% else %} 49 | {% set _ = route_options.append(option) %} 50 | {% endif %} 51 | {% endfor %} 52 | {% if 'gateway' in route %} 53 | {% set route_string = (route.network ~'/'~ route.netmask) | ansible.utils.ipaddr('network/prefix') ~ ',' ~ route.gateway %} 54 | {% else %} 55 | {% set route_string = (route.network ~'/'~ route.netmask) | ansible.utils.ipaddr('network/prefix') %} 56 | {% endif %} 57 | route{{ loop.index }}={{ route_string }} 58 | {% if 'table' in route %} 59 | {# networkmanager wants a table id, so we need to find it in interfaces_route_tables #} 60 | {% set table_id = (interfaces_route_tables | selectattr('name', 'equalto', route.table) | first).id %} 61 | {% set _ = route_options.append('table=' ~ table_id) %} 62 | {% endif %} 63 | {% if route_options | length %} 64 | route{{ loop.index }}_options={{ route_options | join(',') }} 65 | {% endif %} 66 | {% endfor %} 67 | {% for rule in item.rules | default([]) %} 68 | {% if rule is mapping %} 69 | {# networkmanager wants a table id, so we need to find it in interfaces_route_tables #} 70 | {% set table_id = (interfaces_route_tables | selectattr('name', 'equalto', rule.table) | first).id %} 71 | {% if rule.to is defined %} 72 | routing-rule{{ loop.index }}=priority {{ rule.priority | default(32765 - loop.index0) }} to {{ rule.to }} table {{ table_id }} 73 | {% endif %} 74 | {% if rule.from is defined %} 75 | routing-rule{{ loop.index }}=priority {{ rule.priority | default(32765 - loop.index0) }} from {{ rule.from }} table {{ table_id }} 76 | {% endif %} 77 | {% else %} 78 | routing-rule{{ loop.index }}=priority {{ 32765 - loop.index0 }} {{ rule }} 79 | {% endif %} 80 | {% endfor %} 81 | {% if item.dnsnameservers is defined %} 82 | {% if item.dnsnameservers is not string %} 83 | dns={{ item.dnsnameservers | join(';') }}; 84 | {% else %} 85 | dns={{ item.dnsnameservers }} 86 | {% endif %} 87 | {% endif %} 88 | {% if item.dnssearch is defined %} 89 | {% if item.dnssearch is not string %} 90 | dns-search={{ item.dnssearch | join(';') }}; 91 | {% else %} 92 | dns-search={{ item.dnssearch }} 93 | {% endif %} 94 | {% endif %} 95 | 96 | [ipv6] 97 | {% if item.ip6 is defined %} 98 | method={{ (item.bootproto == 'static') | ternary('manual', 'auto') }} 99 | {% if item.ip6.address is defined and item.ip6.netmask is defined %} 100 | address1={{ (item.ip6.address ~'/'~ item.ip6.netmask) | ansible.utils.ipaddr('host/prefix') }} 101 | {% endif %} 102 | {% if item.ip6.gateway is defined %} 103 | gateway={{ item.ip6.gateway }} 104 | {% endif %} 105 | {% for route in item.ip6.route | default([]) %} 106 | {% if 'gateway' in route %} 107 | route{{ loop.index }}={{ (route.network ~'/'~ route.netmask) | ansible.utils.ipaddr('network/prefix') }},{{ route.gateway }} 108 | {% endif %} 109 | {# TODO: dev, table, options #} 110 | {% endfor %} 111 | {% else %} 112 | method=disabled 113 | {% endif %} 114 | -------------------------------------------------------------------------------- /tasks/redhat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: RedHat | install current/latest network packages versions 3 | become: true 4 | package: 5 | name: '{{ interfaces_pkgs }}' 6 | state: '{{ interfaces_pkg_state }}' 7 | tags: package 8 | when: not interfaces_use_networkmanager 9 | 10 | - name: RedHat | install NM-dispatcher-routing-rules 11 | become: true 12 | package: 13 | name: NetworkManager-dispatcher-routing-rules 14 | state: '{{ interfaces_pkg_state }}' 15 | tags: package 16 | when: 17 | - interfaces_use_networkmanager 18 | - not interfaces_use_nmconnection 19 | - interfaces_route_tables | length > 0 20 | notify: Restart NetworkManager 21 | 22 | - name: RedHat | add MichaelRigart.interfaces network-manager config overrides 23 | copy: 24 | content: | 25 | # Ansible managed 26 | [connection] 27 | connection.autoconnect-slaves=1 28 | dest: /etc/NetworkManager/conf.d/80-rigart-interfaces.conf 29 | notify: Reload NetworkManager 30 | become: true 31 | 32 | # CentOS 8/9 cloud images ship with ifcfg files for ens3 and eth0. ifcfg-ens3 33 | # seems to be a relic from the image build process, and causes the network 34 | # service to fail. ifcfg-eth0 is useful for most virtual machines, but if a 35 | # cloud image is deployed on bare metal and eth0 is absent, the network service 36 | # will fail. Remove these files if the interface does not exist or is not being 37 | # configured. 38 | 39 | - name: RedHat | network-scripts remove invalid interface configuration 40 | become: true 41 | file: 42 | path: "/etc/sysconfig/network-scripts/ifcfg-{{ item }}" 43 | state: absent 44 | when: 45 | - item not in ansible_facts.interfaces 46 | - item not in interfaces_ether_interfaces | map(attribute='device') | list 47 | - item not in interfaces_bridge_interfaces | map(attribute='device') | list 48 | - item not in interfaces_bridge_interfaces | map(attribute='ports') | flatten | list 49 | - item not in interfaces_bond_interfaces | map(attribute='device') | list 50 | - item not in interfaces_bond_interfaces | map(attribute='bond_slaves') | flatten | list 51 | with_items: "{{ interfaces_workaround_centos_remove }}" 52 | 53 | - name: RedHat | network-manager remove invalid interface configuration 54 | become: true 55 | file: 56 | path: "/etc/NetworkManager/system-connections/{{ item }}.nmconnection" 57 | state: absent 58 | when: 59 | - item not in ansible_facts.interfaces 60 | - item not in interfaces_ether_interfaces | map(attribute='device') | list 61 | - item not in interfaces_bridge_interfaces | map(attribute='device') | list 62 | - item not in interfaces_bridge_interfaces | map(attribute='ports') | flatten | list 63 | - item not in interfaces_bond_interfaces | map(attribute='device') | list 64 | - item not in interfaces_bond_interfaces | map(attribute='bond_slaves') | flatten | list 65 | with_items: "{{ interfaces_workaround_centos_remove }}" 66 | 67 | # When using NetworkManager with system-connections store, existing ifcfg files 68 | # need to be removed, otherwise they shadow our nmconnection files. We do this 69 | # only for interfaces that we manage in this role. 70 | - name: RedHat | remove network-scripts/ifcfg configuration for NM/system-connections 71 | become: true 72 | file: 73 | path: "/etc/sysconfig/network-scripts/ifcfg-{{ item }}" 74 | state: absent 75 | when: 76 | - interfaces_use_nmconnection 77 | with_items: 78 | - "{{ interfaces_ether_interfaces | map(attribute='device') | list }}" 79 | - "{{ interfaces_bridge_interfaces | map(attribute='device') | list }}" 80 | - "{{ interfaces_bridge_interfaces | map(attribute='ports') | flatten | list }}" 81 | - "{{ interfaces_bond_interfaces | map(attribute='device') | list }}" 82 | - "{{ interfaces_bond_interfaces | map(attribute='bond_slaves') | flatten | list }}" 83 | 84 | # When using the cloud-init network-manager renderer, an nmconnection file may 85 | # have been created with the name cloud-init-{interface}.nmconnection. Delete 86 | # it if we manage the same interface to avoid conflicts. 87 | - name: RedHat | remove NM/system-connections generated by cloud-init 88 | become: true 89 | file: 90 | path: "/etc/NetworkManager/system-connections/cloud-init-{{ item }}.nmconnection" 91 | state: absent 92 | when: 93 | - interfaces_use_nmconnection 94 | with_items: 95 | - "{{ interfaces_ether_interfaces | map(attribute='device') | list }}" 96 | - "{{ interfaces_bridge_interfaces | map(attribute='device') | list }}" 97 | - "{{ interfaces_bridge_interfaces | map(attribute='ports') | flatten | list }}" 98 | - "{{ interfaces_bond_interfaces | map(attribute='device') | list }}" 99 | - "{{ interfaces_bond_interfaces | map(attribute='bond_slaves') | flatten | list }}" 100 | 101 | - name: Flush Handlers 102 | meta: flush_handlers 103 | -------------------------------------------------------------------------------- /templates/bond_nmconnection.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [connection] 4 | id={{ item.device }} 5 | type=bond 6 | interface-name={{ item.device }} 7 | {% if item.zone is defined %} 8 | zone={{ item.zone }} 9 | {% endif %} 10 | 11 | {% for bridge in interfaces_bridge_interfaces %} 12 | {% if item.device in bridge.ports %} 13 | master={{ bridge.device }} 14 | slave-type=bridge 15 | {% endif %} 16 | {% endfor %} 17 | 18 | {% if item.mtu is defined %} 19 | [ethernet] 20 | mtu={{ item.mtu }} 21 | {% endif %} 22 | 23 | [bond] 24 | {% if item.bond_ad_select is defined %} 25 | ad_select={{ item.bond_ad_select }} 26 | {% endif %} 27 | {% if item.bond_downdelay is defined %} 28 | downdelay={{ item.bond_downdelay }} 29 | {% endif %} 30 | {% if item.bond_lacp_rate is defined %} 31 | lacp_rate={{ item.bond_lacp_rate }} 32 | {% endif %} 33 | miimon={{ item.bond_miimon | default(100) }} 34 | {% if item.bond_mode is defined %} 35 | mode={{ item.bond_mode }} 36 | {% endif %} 37 | {% if item.bond_updelay is defined %} 38 | updelay={{ item.bond_updelay }} 39 | {% endif %} 40 | {% if item.bond_xmit_hash_policy is defined %} 41 | xmit_hash_policy={{ item.bond_xmit_hash_policy }} 42 | {% endif %} 43 | 44 | [ipv4] 45 | {% if item.bootproto == 'dhcp' %} 46 | method=auto 47 | {% elif item.bootproto == 'static' and item.address is defined and item.address | length %} 48 | method=manual 49 | {% if item.netmask is defined %} 50 | address1={{ (item.address ~'/'~ item.netmask) | ansible.utils.ipaddr('host/prefix') }} 51 | {% endif %} 52 | {% if item.gateway is defined and item.gateway | length %} 53 | gateway={{ item.gateway }} 54 | {% endif %} 55 | {% else %} 56 | method=disabled 57 | {% endif %} 58 | {% for route in item.route | default([]) %} 59 | {% set route_options = [] %} 60 | {# Ignoring dev option - needed in Network Scripts #} 61 | {# as it is not needed in Network Manager #} 62 | {% for option in route.options | default([]) | reject('match', '^dev ') %} 63 | {% if option is mapping %} 64 | {# We're gonna assume it's a mapping of one key with value, and #} 65 | {# since dict2items returns an array, we're selecting the first item #} 66 | {% set option = option | dict2items | first %} 67 | {% set _ = route_options.append(option.key ~ '=' ~ option.value) %} 68 | {% elif option in ['onlink', 'lock-window', 'lock-cwdn', 'lock-mtu'] %} 69 | {% set _ = route_options.append(option ~ '=true') %} 70 | {% else %} 71 | {% set _ = route_options.append(option) %} 72 | {% endif %} 73 | {% endfor %} 74 | {% if 'gateway' in route %} 75 | {% set route_string = (route.network ~'/'~ route.netmask) | ansible.utils.ipaddr('network/prefix') ~ ',' ~ route.gateway %} 76 | {% else %} 77 | {% set route_string = (route.network ~'/'~ route.netmask) | ansible.utils.ipaddr('network/prefix') %} 78 | {% endif %} 79 | route{{ loop.index }}={{ route_string }} 80 | {% if 'table' in route %} 81 | {# networkmanager wants a table id, so we need to find it in interfaces_route_tables #} 82 | {% set table_id = (interfaces_route_tables | selectattr('name', 'equalto', route.table) | first).id %} 83 | {% set _ = route_options.append('table=' ~ table_id) %} 84 | {% endif %} 85 | {% if route_options | length %} 86 | route{{ loop.index }}_options={{ route_options | join(',') }} 87 | {% endif %} 88 | {% endfor %} 89 | {% for rule in item.rules | default([]) %} 90 | {% if rule is mapping %} 91 | {# networkmanager wants a table id, so we need to find it in interfaces_route_tables #} 92 | {% set table_id = (interfaces_route_tables | selectattr('name', 'equalto', rule.table) | first).id %} 93 | {% if rule.to is defined %} 94 | routing-rule{{ loop.index }}=priority {{ rule.priority | default(32765 - loop.index0) }} to {{ rule.to }} table {{ table_id }} 95 | {% endif %} 96 | {% if rule.from is defined %} 97 | routing-rule{{ loop.index }}=priority {{ rule.priority | default(32765 - loop.index0) }} from {{ rule.from }} table {{ table_id }} 98 | {% endif %} 99 | {% else %} 100 | routing-rule{{ loop.index }}=priority {{ 32765 - loop.index0 }} {{ rule }} 101 | {% endif %} 102 | {% endfor %} 103 | {% if item.dnsnameservers is defined %} 104 | {% if item.dnsnameservers is not string %} 105 | dns={{ item.dnsnameservers | join(';') }}; 106 | {% else %} 107 | dns={{ item.dnsnameservers }} 108 | {% endif %} 109 | {% endif %} 110 | {% if item.dnssearch is defined %} 111 | {% if item.dnssearch is not string %} 112 | dns-search={{ item.dnssearch | join(';') }}; 113 | {% else %} 114 | dns-search={{ item.dnssearch }} 115 | {% endif %} 116 | {% endif %} 117 | 118 | [ipv6] 119 | {% if item.ip6 is defined %} 120 | method={{ (item.bootproto == 'static') | ternary('manual', 'auto') }} 121 | {% if item.ip6.address is defined and item.ip6.netmask is defined %} 122 | address1={{ (item.ip6.address ~'/'~ item.ip6.netmask) | ansible.utils.ipaddr('host/prefix') }} 123 | {% endif %} 124 | {% if item.ip6.gateway is defined %} 125 | gateway={{ item.ip6.gateway }} 126 | {% endif %} 127 | {% for route in item.ip6.route | default([]) %} 128 | {% if 'gateway' in route %} 129 | route{{ loop.index }}={{ (route.network ~'/'~ route.netmask) | ansible.utils.ipaddr('network/prefix') }},{{ route.gateway }} 130 | {% endif %} 131 | {# TODO: dev, table, options #} 132 | {% endfor %} 133 | {% else %} 134 | method=disabled 135 | {% endif %} 136 | -------------------------------------------------------------------------------- /templates/ethernet_nmconnection.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [connection] 4 | id={{ item.device }} 5 | {% if 'type' in item %} 6 | type={{ item.type }} 7 | {% else %} 8 | type={{ ('vlan' if item.device is match(vlan_interface_regex) else 'dummy' if item.device is match(dummy_interface_regex) else 'ethernet') }} 9 | {% endif %} 10 | interface-name={{ item.device }} 11 | {% if item.zone is defined %} 12 | zone={{ item.zone }} 13 | {% endif %} 14 | 15 | {% for bridge in interfaces_bridge_interfaces %} 16 | {% if item.device in bridge.ports %} 17 | master={{ bridge.device }} 18 | slave-type=bridge 19 | {% endif %} 20 | {% endfor %} 21 | 22 | {% if item.mtu is defined %} 23 | [ethernet] 24 | mtu={{ item.mtu }} 25 | {% endif %} 26 | 27 | {% if item.device is match(vlan_interface_regex) %} 28 | [vlan] 29 | interface-name={{ item.device }} 30 | parent={{ item.device | regex_replace(vlan_interface_regex, '\g') }} 31 | id={{ item.device | regex_replace(vlan_interface_regex, '\g') }} 32 | {% if item.ingress_priority_map is defined %} 33 | ingress-priority-map={{ item.ingress_priority_map }} 34 | {% endif %} 35 | {% if item.egress_priority_map is defined %} 36 | egress-priority-map={{ item.egress_priority_map }} 37 | {% endif %} 38 | {% endif %} 39 | 40 | {% if 'type' in item %} 41 | {% if item.type == 'loopback' %} 42 | [loopback] 43 | 44 | {% endif %} 45 | {% endif %} 46 | [ipv4] 47 | {% if item.bootproto == 'dhcp' %} 48 | method=auto 49 | {% elif item.bootproto == 'static' and item.address is defined and item.address | length %} 50 | method=manual 51 | {% if item.netmask is defined %} 52 | address1={{ (item.address ~'/'~ item.netmask) | ansible.utils.ipaddr('host/prefix') }} 53 | {% endif %} 54 | {% if item.gateway is defined and item.gateway | length %} 55 | gateway={{ item.gateway }} 56 | {% endif %} 57 | {% else %} 58 | method=disabled 59 | {% endif %} 60 | {% for route in item.route | default([]) %} 61 | {% set route_options = [] %} 62 | {# Ignoring dev option - needed in Network Scripts #} 63 | {# as it is not needed in Network Manager #} 64 | {% for option in route.options | default([]) | reject('match', '^dev ') %} 65 | {% if option is mapping %} 66 | {# We're gonna assume it's a mapping of one key with value, and #} 67 | {# since dict2items returns an array, we're selecting the first item #} 68 | {% set option = option | dict2items | first %} 69 | {% set _ = route_options.append(option.key ~ '=' ~ option.value) %} 70 | {% elif option in ['onlink', 'lock-window', 'lock-cwdn', 'lock-mtu'] %} 71 | {% set _ = route_options.append(option ~ '=true') %} 72 | {% else %} 73 | {% set _ = route_options.append(option) %} 74 | {% endif %} 75 | {% endfor %} 76 | {% if 'gateway' in route %} 77 | {% set route_string = (route.network ~'/'~ route.netmask) | ansible.utils.ipaddr('network/prefix') ~ ',' ~ route.gateway %} 78 | {% else %} 79 | {% set route_string = (route.network ~'/'~ route.netmask) | ansible.utils.ipaddr('network/prefix') %} 80 | {% endif %} 81 | route{{ loop.index }}={{ route_string }} 82 | {% if 'table' in route %} 83 | {# networkmanager wants a table id, so we need to find it in interfaces_route_tables #} 84 | {% set table_id = (interfaces_route_tables | selectattr('name', 'equalto', route.table) | first).id %} 85 | {% set _ = route_options.append('table=' ~ table_id) %} 86 | {% endif %} 87 | {% if route_options | length %} 88 | route{{ loop.index }}_options={{ route_options | join(',') }} 89 | {% endif %} 90 | {% endfor %} 91 | {% for rule in item.rules | default([]) %} 92 | {% if rule is mapping %} 93 | {# networkmanager wants a table id, so we need to find it in interfaces_route_tables #} 94 | {% set table_id = (interfaces_route_tables | selectattr('name', 'equalto', rule.table) | first).id %} 95 | {% if rule.to is defined %} 96 | routing-rule{{ loop.index }}=priority {{ rule.priority | default(32765 - loop.index0) }} to {{ rule.to }} table {{ table_id }} 97 | {% endif %} 98 | {% if rule.from is defined %} 99 | routing-rule{{ loop.index }}=priority {{ rule.priority | default(32765 - loop.index0) }} from {{ rule.from }} table {{ table_id }} 100 | {% endif %} 101 | {% else %} 102 | routing-rule{{ loop.index }}=priority {{ 32765 - loop.index0 }} {{ rule }} 103 | {% endif %} 104 | {% endfor %} 105 | {% if item.dnsnameservers is defined %} 106 | {% if item.dnsnameservers is not string %} 107 | dns={{ item.dnsnameservers | join(';') }}; 108 | {% else %} 109 | dns={{ item.dnsnameservers }} 110 | {% endif %} 111 | {% endif %} 112 | {% if item.dnssearch is defined %} 113 | {% if item.dnssearch is not string %} 114 | dns-search={{ item.dnssearch | join(';') }}; 115 | {% else %} 116 | dns-search={{ item.dnssearch }} 117 | {% endif %} 118 | {% endif %} 119 | 120 | [ipv6] 121 | {% if item.ip6 is defined %} 122 | method={{ (item.bootproto == 'static') | ternary('manual', 'auto') }} 123 | {% if item.ip6.address is defined and item.ip6.netmask is defined %} 124 | address1={{ (item.ip6.address ~'/'~ item.ip6.netmask) | ansible.utils.ipaddr('host/prefix') }} 125 | {% endif %} 126 | {% if item.ip6.gateway is defined %} 127 | gateway={{ item.ip6.gateway }} 128 | {% endif %} 129 | {% for route in item.ip6.route | default([]) %} 130 | {% if 'gateway' in route %} 131 | route{{ loop.index }}={{ (route.network ~'/'~ route.netmask) | ansible.utils.ipaddr('network/prefix') }},{{ route.gateway }} 132 | {% endif %} 133 | {# TODO: dev, table, options #} 134 | {% endfor %} 135 | {% else %} 136 | method=disabled 137 | {% endif %} 138 | -------------------------------------------------------------------------------- /tasks/ethernet_configuration.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Check active Ethernet interface state 3 | debug: 4 | msg: > 5 | Checking Ethernet interface configuration for {{ item.device }}: 6 | {{ ether_check }} 7 | with_items: "{{ interfaces_ether_interfaces }}" 8 | changed_when: ether_check.diff 9 | register: ether_check_result 10 | notify: 11 | - Bounce network devices 12 | vars: 13 | ether_check: "{{ item | ether_check }}" 14 | 15 | - name: Create the network configuration file for ethernet devices 16 | become: true 17 | template: 18 | src: "ethernet_{{ interfaces_use_nmconnection | ternary('nmconnection', ansible_facts.os_family) }}.j2" 19 | dest: "{{ interfaces_net_path }}/{{ interfaces_use_nmconnection | ternary(item.device ~ '.nmconnection', 'ifcfg-' ~ item.device) }}" 20 | mode: "{{ interfaces_use_nmconnection | ternary('0600', omit) }}" 21 | with_items: '{{ interfaces_ether_interfaces }}' 22 | register: ether_result 23 | notify: 24 | - Bounce network devices 25 | 26 | - name: RedHat | Write configuration files for rhel route configuration 27 | become: true 28 | template: 29 | src: 'route_{{ ansible_facts.os_family }}.j2' 30 | dest: '{{ interfaces_net_path }}/route-{{ item.device }}' 31 | with_items: '{{ interfaces_ether_interfaces }}' 32 | when: 33 | - item.route is defined 34 | - ansible_facts.os_family == 'RedHat' 35 | - not interfaces_use_nmconnection 36 | register: ether_route_add_result 37 | notify: 38 | - Bounce network devices 39 | 40 | - name: RedHat | Write configuration files for rhel v6 route configuration 41 | become: true 42 | template: 43 | src: 'route6_{{ ansible_facts.os_family }}.j2' 44 | dest: '{{ interfaces_net_path }}/route6-{{ item.device }}' 45 | with_items: '{{ interfaces_ether_interfaces }}' 46 | when: 47 | - item.ip6 is defined 48 | - item.ip6.route is defined 49 | - ansible_facts.os_family == 'RedHat' 50 | - not interfaces_use_nmconnection 51 | register: ether_route6_add_result 52 | notify: 53 | - Bounce network devices 54 | 55 | - name: RedHat | Remove configuration files for rhel route configuration 56 | become: true 57 | file: 58 | path: '/etc/sysconfig/network-scripts/route-{{ item.device }}' 59 | state: absent 60 | with_items: '{{ interfaces_ether_interfaces }}' 61 | when: 62 | - item.route is not defined or interfaces_use_nmconnection 63 | - ansible_facts.os_family == 'RedHat' 64 | register: ether_route_del_result 65 | notify: 66 | - Bounce network devices 67 | 68 | - name: RedHat | Remove configuration files for rhel v6 route configuration 69 | become: true 70 | file: 71 | path: '/etc/sysconfig/network-scripts/route6-{{ item.device }}' 72 | state: absent 73 | with_items: '{{ interfaces_ether_interfaces }}' 74 | when: 75 | - item.ip6 is not defined or interfaces_use_nmconnection 76 | - ansible_facts.os_family == 'RedHat' 77 | register: ether_route6_del_result 78 | notify: 79 | - Bounce network devices 80 | 81 | - name: RedHat | Write configuration files for rhel rule configuration 82 | become: true 83 | template: 84 | src: 'rule_{{ ansible_facts.os_family }}.j2' 85 | dest: '{{ interfaces_net_path }}/rule-{{ item.device }}' 86 | with_items: '{{ interfaces_ether_interfaces }}' 87 | when: 88 | - item.rules is defined 89 | - ansible_facts.os_family == 'RedHat' 90 | - not interfaces_use_nmconnection 91 | register: ether_rule_add_result 92 | notify: 93 | - Bounce network devices 94 | 95 | - name: RedHat | Remove configuration files for rhel rule configuration 96 | become: true 97 | file: 98 | path: '/etc/sysconfig/network-scripts/rule-{{ item.device }}' 99 | state: absent 100 | with_items: '{{ interfaces_ether_interfaces }}' 101 | when: 102 | - item.rules is not defined or interfaces_use_nmconnection 103 | - ansible_facts.os_family == 'RedHat' 104 | register: ether_rule_del_result 105 | notify: 106 | - Bounce network devices 107 | 108 | # ether_interfaces_changed is used in the 'Bounce network devices' handler. 109 | - name: Set a fact containing changed ethernet devices 110 | vars: 111 | # Build a list of all Ethernet results. 112 | all_ether_results: > 113 | {{ ether_check_result.results | default([]) + 114 | ether_result.results | default([]) + 115 | ether_route_add_result.results | default([]) + 116 | ether_route_del_result.results | default([]) + 117 | ether_route6_add_result.results | default([]) + 118 | ether_route6_del_result.results | default([]) + 119 | ether_rule_add_result.results | default([]) + 120 | ether_rule_del_result.results | default([]) }} 121 | # Select those tasks which changed, and map to a list of the corresponding 122 | # Ethernet devices. 123 | ether_interfaces_changed: > 124 | {{ all_ether_results | 125 | select('changed') | 126 | map(attribute='item.device') | 127 | unique | 128 | list }} 129 | vlan_on_changed_interface_regex: "{{ '(' ~ ((ether_interfaces_changed + bond_master_interfaces_changed + bridge_interfaces_changed) | join('|')) ~ ')' ~ vlan_interface_suffix_regex }}" 130 | # Find VLAN interfaces which have a changed parent device. At least on 131 | # CentOS/RHEL 7 systems, any static routes on the VLAN interface are lost 132 | # if the parent goes down. 133 | vlans_on_changed_interfaces: > 134 | {{ all_ether_results | 135 | map(attribute='item.device') | 136 | select('match', vlan_on_changed_interface_regex) | 137 | unique | 138 | list }} 139 | set_fact: 140 | ether_interfaces_changed: "{{ (ether_interfaces_changed + vlans_on_changed_interfaces) | unique | list}}" 141 | -------------------------------------------------------------------------------- /tasks/bridge_configuration.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Check active bridge interface state 3 | debug: 4 | msg: > 5 | Checking bridge interface configuration for {{ item.device }}: 6 | {{ bridge_check }} 7 | with_items: "{{ interfaces_bridge_interfaces }}" 8 | changed_when: bridge_check.diff 9 | register: bridge_check_result 10 | notify: 11 | - Bounce network devices 12 | vars: 13 | bridge_check: "{{ item | bridge_check }}" 14 | 15 | - name: Create the network configuration file for bridge devices 16 | become: true 17 | template: 18 | src: "bridge_{{ interfaces_use_nmconnection | ternary('nmconnection', ansible_facts.os_family) }}.j2" 19 | dest: "{{ interfaces_net_path }}/{{ interfaces_use_nmconnection | ternary(item.device ~ '.nmconnection', 'ifcfg-' ~ item.device) }}" 20 | mode: "{{ interfaces_use_nmconnection | ternary('0600', omit) }}" 21 | with_items: '{{ interfaces_bridge_interfaces }}' 22 | register: bridge_result 23 | notify: 24 | - Bounce network devices 25 | 26 | - name: RedHat | Write configuration files for rhel route configuration 27 | become: true 28 | template: 29 | src: 'route_{{ ansible_facts.os_family }}.j2' 30 | dest: '{{ interfaces_net_path }}/route-{{ item.device }}' 31 | with_items: '{{ interfaces_bridge_interfaces }}' 32 | when: 33 | - item.route is defined 34 | - ansible_facts.os_family == 'RedHat' 35 | - not interfaces_use_nmconnection 36 | register: bridge_route_add_result 37 | notify: 38 | - Bounce network devices 39 | 40 | - name: RedHat | Remove configuration files for rhel route configuration 41 | become: true 42 | file: 43 | path: '/etc/sysconfig/network-scripts/route-{{ item.device }}' 44 | state: absent 45 | with_items: '{{ interfaces_bridge_interfaces }}' 46 | when: 47 | - item.route is not defined or interfaces_use_nmconnection 48 | - ansible_facts.os_family == 'RedHat' 49 | register: bridge_route_del_result 50 | notify: 51 | - Bounce network devices 52 | 53 | - name: RedHat | Write configuration files for rhel rule configuration 54 | become: true 55 | template: 56 | src: 'rule_{{ ansible_facts.os_family }}.j2' 57 | dest: '{{ interfaces_net_path }}/rule-{{ item.device }}' 58 | with_items: '{{ interfaces_bridge_interfaces }}' 59 | when: 60 | - item.rules is defined 61 | - ansible_facts.os_family == 'RedHat' 62 | - not interfaces_use_nmconnection 63 | register: bridge_rule_add_result 64 | notify: 65 | - Bounce network devices 66 | 67 | - name: RedHat | Remove configuration files for rhel rule configuration 68 | become: true 69 | file: 70 | path: '/etc/sysconfig/network-scripts/rule-{{ item.device }}' 71 | state: absent 72 | with_items: '{{ interfaces_bridge_interfaces }}' 73 | when: 74 | - item.rules is not defined or interfaces_use_nmconnection 75 | - ansible_facts.os_family == 'RedHat' 76 | register: bridge_rule_del_result 77 | notify: 78 | - Bounce network devices 79 | 80 | - name: Create the network configuration file for port on the bridge devices 81 | become: true 82 | template: 83 | src: "bridge_port_{{ interfaces_use_nmconnection | ternary('nmconnection', ansible_facts.os_family) }}.j2" 84 | dest: "{{ interfaces_net_path }}/{{ interfaces_use_nmconnection | ternary(item.1 ~ '.nmconnection', 'ifcfg-' ~ item.1) }}" 85 | mode: "{{ interfaces_use_nmconnection | ternary('0600', omit) }}" 86 | with_subelements: 87 | - "{{ interfaces_bridge_interfaces }}" 88 | - ports 89 | # Don't configure bridge ports that are bonds here - they will have been 90 | # configured by the bond tasks. 91 | when: 92 | - item.1 not in interfaces_bond_interfaces | map(attribute='device') | list 93 | register: bridge_port_result 94 | notify: 95 | - Bounce network devices 96 | 97 | - name: Set a fact containing all bridge results 98 | set_fact: 99 | # Build a list of all bridge results. 100 | all_bridge_results: > 101 | {{ bridge_check_result.results | default([]) + 102 | bridge_result.results | default([]) + 103 | bridge_route_add_result.results | default([]) + 104 | bridge_route_del_result.results | default([]) + 105 | bridge_rule_add_result.results | default([]) + 106 | bridge_rule_del_result.results | default([]) }} 107 | # Find bridge interfaces which have all ports changed. We do this by 108 | # excluding any bridges which have an unchanged port. 109 | bridge_interfaces_with_all_ports_changed: > 110 | {{ interfaces_bridge_interfaces | 111 | map(attribute='device') | 112 | difference(bridge_port_result.results | 113 | reject('changed') | 114 | map(attribute='item.0.device') | 115 | list) | 116 | list }} 117 | 118 | # bridge_interfaces_changed and bridge_port_interfaces_changed are used in the 119 | # 'Bounce network devices' handler. 120 | - name: Set facts containing changed bridge and bridge port devices 121 | set_fact: 122 | # Select those tasks which changed, and map to a list of the corresponding 123 | # bridge devices. 124 | # On CentOS/RHEL 8 systems, if all ports of a bridge go down, the bridge 125 | # interface will also go down. If the ports are brought back up again, 126 | # the bridge interface does not automatically come back up. Add bridge 127 | # interfaces which have all ports changed to the list. 128 | bridge_interfaces_changed: > 129 | {{ (all_bridge_results | 130 | select('changed') | 131 | map(attribute='item.device') | 132 | list + 133 | bridge_interfaces_with_all_ports_changed) | 134 | unique | 135 | list }} 136 | # Select those tasks which changed, and map to a list of the corresponding 137 | # bridge port devices. 138 | bridge_port_interfaces_changed: > 139 | {{ bridge_port_result.results | 140 | select('changed') | 141 | map(attribute='item.1') | 142 | unique | 143 | list }} 144 | -------------------------------------------------------------------------------- /tasks/bond_configuration.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Check active bond interface state 3 | debug: 4 | msg: > 5 | Checking bond interface configuration for {{ item.device }}: 6 | {{ bond_check }} 7 | with_items: "{{ interfaces_bond_interfaces }}" 8 | changed_when: bond_check.diff 9 | register: bond_check_result 10 | notify: 11 | - Bounce network devices 12 | vars: 13 | bond_check: "{{ item | bond_check }}" 14 | 15 | - name: Create the network configuration file for bond devices 16 | become: true 17 | template: 18 | src: "bond_{{ interfaces_use_nmconnection | ternary('nmconnection', ansible_facts.os_family) }}.j2" 19 | dest: "{{ interfaces_net_path }}/{{ interfaces_use_nmconnection | ternary(item.device ~ '.nmconnection', 'ifcfg-' ~ item.device) }}" 20 | mode: "{{ interfaces_use_nmconnection | ternary('0600', omit) }}" 21 | with_items: '{{ interfaces_bond_interfaces }}' 22 | register: bond_result 23 | notify: 24 | - Check whether /etc/modules-load.d exists 25 | - Make sure the bonding module is loaded 26 | - Make sure the bonding module is loaded at boot via /etc/modules-load.d 27 | - Make sure the bonding module is loaded at boot via /etc/modules 28 | - Bounce network devices 29 | 30 | - name: RedHat | Write configuration files for rhel route configuration 31 | become: true 32 | template: 33 | src: 'route_{{ ansible_facts.os_family }}.j2' 34 | dest: '{{ interfaces_net_path }}/route-{{ item.device }}' 35 | with_items: '{{ interfaces_bond_interfaces }}' 36 | when: 37 | - item.route is defined 38 | - ansible_facts.os_family == 'RedHat' 39 | - not interfaces_use_nmconnection 40 | register: bond_route_add_result 41 | notify: 42 | - Bounce network devices 43 | 44 | - name: RedHat | Remove configuration files for rhel route configuration 45 | become: true 46 | file: 47 | path: '/etc/sysconfig/network-scripts/route-{{ item.device }}' 48 | state: absent 49 | with_items: '{{ interfaces_bond_interfaces }}' 50 | when: 51 | - item.route is not defined or interfaces_use_nmconnection 52 | - ansible_facts.os_family == 'RedHat' 53 | register: bond_route_del_result 54 | notify: 55 | - Bounce network devices 56 | 57 | - name: RedHat | Write configuration files for rhel rule configuration 58 | become: true 59 | template: 60 | src: 'rule_{{ ansible_facts.os_family }}.j2' 61 | dest: '{{ interfaces_net_path }}/rule-{{ item.device }}' 62 | with_items: '{{ interfaces_bond_interfaces }}' 63 | when: 64 | - item.rules is defined 65 | - ansible_facts.os_family == 'RedHat' 66 | - not interfaces_use_nmconnection 67 | register: bond_rule_add_result 68 | notify: 69 | - Bounce network devices 70 | 71 | - name: RedHat | Remove configuration files for rhel rule configuration 72 | become: true 73 | file: 74 | path: '/etc/sysconfig/network-scripts/rule-{{ item.device }}' 75 | state: absent 76 | with_items: '{{ interfaces_bond_interfaces }}' 77 | when: 78 | - item.rules is not defined or interfaces_use_nmconnection 79 | - ansible_facts.os_family == 'RedHat' 80 | register: bond_rule_del_result 81 | notify: 82 | - Bounce network devices 83 | 84 | - name: Create the network configuration file for slave in the bond devices 85 | become: true 86 | template: 87 | src: "bond_slave_{{ interfaces_use_nmconnection | ternary('nmconnection', ansible_facts.os_family) }}.j2" 88 | dest: "{{ interfaces_net_path }}/{{ interfaces_use_nmconnection | ternary(item.1 ~ '.nmconnection', 'ifcfg-' ~ item.1) }}" 89 | mode: "{{ interfaces_use_nmconnection | ternary('0600', omit) }}" 90 | with_subelements: 91 | - "{{ interfaces_bond_interfaces }}" 92 | - bond_slaves 93 | when: 94 | - interfaces_bond_setup_slaves 95 | register: bond_slave_result 96 | notify: 97 | - Bounce network devices 98 | 99 | - name: Set a fact containing all bond master results 100 | set_fact: 101 | # Build a list of all bond master results. 102 | all_bond_master_results: > 103 | {{ bond_check_result.results | default([]) + 104 | bond_result.results | default([]) + 105 | bond_route_add_result.results | default([]) + 106 | bond_route_del_result.results | default([]) + 107 | bond_rule_add_result.results | default([]) + 108 | bond_rule_del_result.results | default([]) }} 109 | # Find bond interfaces which have all members changed. We do this by 110 | # excluding any bonds which have an unchanged member. 111 | bond_master_interfaces_with_all_slaves_changed: > 112 | {{ interfaces_bond_interfaces | 113 | map(attribute='device') | 114 | difference(bond_slave_result.results | 115 | reject('changed') | 116 | map(attribute='item.0.device') | 117 | list) | 118 | list }} 119 | 120 | # bond_master_interfaces_changed and bond_slave_interfaces_changed are used in 121 | # the 'Bounce network devices' handler. 122 | - name: Set facts containing changed bond master and slave devices 123 | set_fact: 124 | # Select those tasks which changed, and map to a list of the corresponding 125 | # bond master devices. 126 | # On CentOS/RHEL systems, if all members in a bond go down, the bond 127 | # interface will also go down. If the members are brought back up again, 128 | # the bond interface does not automatically come back up. Add bond 129 | # interfaces which have all members changed to the list. 130 | bond_master_interfaces_changed: > 131 | {{ (all_bond_master_results | 132 | select('changed') | 133 | map(attribute='item.device') | 134 | list + 135 | bond_master_interfaces_with_all_slaves_changed) | 136 | unique | 137 | list }} 138 | # Select those tasks which changed, and map to a list of the corresponding 139 | # bond slave devices. 140 | bond_slave_interfaces_changed: > 141 | {{ bond_slave_result.results | 142 | select('changed') | 143 | map(attribute='item.1') | 144 | unique | 145 | list }} 146 | -------------------------------------------------------------------------------- /filter_plugins/filters.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 StackHPC Ltd. 2 | 3 | import re 4 | 5 | # NOTE: jinja2 3.1.0 dropped contextfilter in favour of pass_context. 6 | try: 7 | from jinja2 import pass_context 8 | except ImportError: 9 | from jinja2 import contextfilter as pass_context 10 | 11 | 12 | def _fail(reason): 13 | return { 14 | "diff": True, 15 | "reason": reason, 16 | } 17 | 18 | 19 | def _pass(): 20 | return {"diff": False} 21 | 22 | 23 | def _device(interface): 24 | """Return the device associated with an interface.""" 25 | return interface["device"] 26 | 27 | 28 | def _fact_name(device): 29 | """Return the name of the Ansible fact associated with an interface.""" 30 | # Ansible fact names replace dashes and colons with an underscore. 31 | return re.sub(r"[\-\:]", "_", device) 32 | 33 | 34 | def _fact(context, device): 35 | """Return the fact associated with an interface.""" 36 | fact_name = _fact_name(device) 37 | return context["ansible_facts"][fact_name] 38 | 39 | 40 | def _interface_check(context, interface, interface_type=None): 41 | """Check whether the active state of an Ethernet interface is as requested. 42 | 43 | :param context: Jinja2 context. 44 | :param interface: An item in interfaces_ether_interfaces. 45 | :param interface_type: The expected interface type. 46 | :returns: A dict containing 'diff' and 'reason' items. 47 | """ 48 | device = _device(interface) 49 | 50 | # Existence 51 | fact_name = _fact_name(device) 52 | if fact_name not in context["ansible_facts"]: 53 | return _fail("Interface %s does not exist" % device) 54 | 55 | fact = _fact(context, device) 56 | 57 | # Interfaces with a colon (:) in their name are subinterfaces - effectively 58 | # secondary IP addresses on another interface. 59 | if ':' not in device: 60 | # State 61 | if not fact.get("active") and not bool(interface.get("ignore_status_check")): 62 | return _fail("Interface %s is not active" % device) 63 | 64 | # Type 65 | if interface_type: 66 | fact_type = fact["type"] 67 | if interface_type != fact_type: 68 | return _fail("Interface %s is of an unexpected type" % device) 69 | 70 | # Static IPv4 address 71 | if interface.get("bootproto") == "static" and interface.get("address"): 72 | fact_address = fact.get("ipv4", {}).get("address") 73 | secondaries = fact.get("ipv4_secondaries", None) 74 | if interface["address"] != "0.0.0.0": 75 | # IP address 76 | if not fact_address: 77 | if not secondaries: 78 | return _fail("Interface %s has no IPv4 address" % device) 79 | 80 | if secondaries: 81 | for address_dict in secondaries: 82 | if interface['address'] == address_dict['address']: 83 | fact['ipv4'] = address_dict 84 | fact_address = address_dict['address'] 85 | 86 | if fact_address != interface["address"]: 87 | return _fail("Interface %s has incorrect IPv4 address" % device) 88 | 89 | # Netmask 90 | if (interface.get("netmask") and 91 | fact["ipv4"]["netmask"] != interface["netmask"]): 92 | return _fail("Interface %s has incorrect IPv4 netmask" % device) 93 | 94 | # Gateway 95 | if interface.get("gateway"): 96 | fact_gateway = context["ansible_facts"].get("default_ipv4", {}).get("gateway") 97 | if not fact_gateway: 98 | return _fail("Default IPv4 gateway is missing") 99 | if interface["gateway"] != fact_gateway: 100 | return _fail("Default IPv4 gateway is incorrect") 101 | 102 | elif fact_address and fact_address not in interface.get('allowed_addresses', []): 103 | return _fail("Interface %s has an IPv4 address but none was " 104 | "requested" % device) 105 | 106 | # Static IPv6 address 107 | if interface.get("bootproto") == "static" and interface.get("ip6"): 108 | fact_address = fact.get("ipv6", []) 109 | # IP address 110 | if len(fact_address) == 0: 111 | return _fail("Interface %s has no IPv6 address" % device) 112 | 113 | for item in fact_address: 114 | if item["address"] == interface["ip6"]["address"] and item["prefix"] == str(interface["ip6"]["prefix"]): 115 | break 116 | else: 117 | return _fail("Interface %s has incorrect IPv6 address" % device) 118 | 119 | # Gateway 120 | if interface["ip6"].get("gateway"): 121 | fact_gateway = context["ansible_facts"].get("default_ipv6", {}).get("gateway") 122 | if not fact_gateway: 123 | return _fail("Default IPv6 gateway is missing") 124 | if interface["ip6"]["gateway"] != fact_gateway: 125 | return _fail("Default IPv6 gateway is incorrect") 126 | 127 | # MTU 128 | if interface.get("mtu"): 129 | fact_mtu = fact.get("mtu") 130 | if interface["mtu"] != fact_mtu: 131 | return _fail("Interface %s has incorrect MTU" % device) 132 | 133 | return _pass() 134 | 135 | 136 | @pass_context 137 | def ether_check(context, interface): 138 | """Check whether the active state of an Ethernet interface is as requested. 139 | 140 | :param context: Jinja2 context. 141 | :param interface: An item in interfaces_ether_interfaces. 142 | :returns: A dict containing 'diff' and 'reason' items. 143 | """ 144 | if interface.get('type') == 'ipoib': 145 | result = _interface_check(context, interface, "infiniband") 146 | elif interface.get('type') == 'loopback': 147 | result = _interface_check(context, interface, "loopback") 148 | else: 149 | result = _interface_check(context, interface, "ether") 150 | return result 151 | 152 | 153 | @pass_context 154 | def bridge_check(context, interface): 155 | """Check whether the active state of a bridge interface is as requested. 156 | 157 | :param context: Jinja2 context. 158 | :param interface: An item in interfaces_ether_interfaces. 159 | :returns: A dict containing 'diff' and 'reason' items. 160 | """ 161 | result = _interface_check(context, interface, "bridge") 162 | if result["diff"]: 163 | return result 164 | 165 | device = _device(interface) 166 | fact = _fact(context, device) 167 | 168 | # Bridge ports 169 | fact_ports = fact.get("interfaces", []) 170 | interface_ports = interface.get("ports", []) 171 | missing = set(interface_ports) - set(fact_ports) 172 | if missing: 173 | return _fail("Bridge interface %s has missing ports: %s" % 174 | (device, ", ".join(missing))) 175 | 176 | for port in interface_ports: 177 | port_interface = {"device": port} 178 | result = _interface_check(context, port_interface) 179 | if result["diff"]: 180 | return result 181 | 182 | return result 183 | 184 | 185 | @pass_context 186 | def bond_check(context, interface): 187 | """Check whether the active state of a bond interface is as requested. 188 | 189 | :param context: Jinja2 context. 190 | :param interface: An item in interfaces_ether_interfaces. 191 | :returns: A dict containing 'diff' and 'reason' items. 192 | """ 193 | result = _interface_check(context, interface, "bonding") 194 | if result["diff"]: 195 | return result 196 | 197 | device = _device(interface) 198 | fact = _fact(context, device) 199 | 200 | # Bond mode 201 | if interface.get("bond_mode"): 202 | fact_mode = fact["mode"] 203 | # Convert numerical modes to the named modes presented by ansible. 204 | mode_lookup = { 205 | "1": "active-backup", 206 | "2": "balance-xor", 207 | "3": "broadcast", 208 | "4": "802.3ad", 209 | "5": "balance-tlb", 210 | "6": "balance-alb", 211 | } 212 | interface_mode = str(interface["bond_mode"]) 213 | interface_mode = mode_lookup.get(interface_mode, interface_mode) 214 | if interface_mode != fact["mode"]: 215 | return _fail("Bond interface %s has incorrect bond mode" % device) 216 | 217 | # Bond miimon 218 | if interface.get("bond_miimon"): 219 | fact_miimon = fact["miimon"] 220 | if str(interface["bond_miimon"]) != fact["miimon"]: 221 | return _fail("Bond interface %s has incorrect miimon" % device) 222 | 223 | # Bond slaves 224 | fact_slaves = fact.get("slaves", []) 225 | interface_slaves = interface.get("bond_slaves", []) 226 | missing = set(interface_slaves) - set(fact_slaves) 227 | if missing: 228 | return _fail("Bond interface %s has missing slaves: %s" % 229 | (device, ", ".join(missing))) 230 | additional = set(fact_slaves) - set(interface_slaves) 231 | if additional: 232 | return _fail("Bond interface %s has additional slaves: %s" % 233 | (device, ", ".join(additional))) 234 | 235 | for slave in interface_slaves: 236 | slave_interface = {"device": slave} 237 | result = _interface_check(context, slave_interface) 238 | if result["diff"]: 239 | return result 240 | 241 | return result 242 | 243 | 244 | class FilterModule(object): 245 | """Interface comparison filters.""" 246 | 247 | def filters(self): 248 | return { 249 | 'ether_check': ether_check, 250 | 'bridge_check': bridge_check, 251 | 'bond_check': bond_check, 252 | } 253 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # NOTE: Handlers are executed in the order in which they are defined, not the 3 | # order in which they are notified. 4 | 5 | # Some systems do not support /etc/modules-load.d, in which case we fall back 6 | # to /etc/modules. 7 | - name: Check whether /etc/modules-load.d exists 8 | become: true 9 | stat: 10 | path: /etc/modules-load.d 11 | register: modules_load_stat 12 | 13 | - name: Make sure the bonding module is loaded 14 | become: true 15 | modprobe: 16 | name: bonding 17 | state: present 18 | 19 | - name: Make sure the bonding module is loaded at boot via /etc/modules-load.d 20 | become: true 21 | template: 22 | src: module.conf.j2 23 | dest: /etc/modules-load.d/bonding.conf 24 | when: modules_load_stat.stat.exists 25 | vars: 26 | module_name: bonding 27 | 28 | - name: Make sure the bonding module is loaded at boot via /etc/modules 29 | become: true 30 | lineinfile: 31 | dest: /etc/modules 32 | line: bonding 33 | when: not modules_load_stat.stat.exists 34 | 35 | - name: Make sure the 8021q module is loaded 36 | become: true 37 | modprobe: 38 | name: 8021q 39 | state: present 40 | 41 | - name: Make sure the 8021q module is loaded at boot via /etc/modules-load.d 42 | become: true 43 | template: 44 | src: module.conf.j2 45 | dest: /etc/modules-load.d/8021q.conf 46 | when: modules_load_stat.stat.exists 47 | vars: 48 | module_name: 8021q 49 | 50 | - name: Make sure the 8021q module is loaded at boot via /etc/modules 51 | become: true 52 | lineinfile: 53 | dest: /etc/modules 54 | line: 8021q 55 | when: not modules_load_stat.stat.exists 56 | 57 | # We need to bounce the changed network interfaces carefully, as some 58 | # interfaces may depend on others. To further complicate matters, the 59 | # dependencies are different between RedHat and Debian systems. Here are the 60 | # possible dependencies between interface types (X -> Y means X depends on Y): 61 | # 62 | # Ethernet (VLAN) -> Ethernet 63 | # Ethernet (VLAN) -> bond master 64 | # Ethernet (VLAN) -> bridge 65 | # [RedHat] Bond master -> bridge 66 | # [RedHat] Bond slave -> bond master 67 | # [Debian] Bond master -> bond slave 68 | # Bond slave (VLAN) -> Ethernet 69 | # [RedHat] bridge port -> bridge 70 | # [Debian] bridge -> bridge port 71 | # [Debian] bridge -> bond master 72 | # Bridge port (VLAN) -> Ethernet 73 | # Bridge port (VLAN) -> bond master 74 | # Bridge port (VLAN) -> bridge 75 | # 76 | # Note that VLAN interfaces as bond slaves do not appear to work on Debian. 77 | # 78 | # This generates a number of valid orderings. For RedHat, we'll go with this 79 | # one: 80 | # - Ethernet (non VLAN) 81 | # - Bridge 82 | # - Bond master 83 | # - Bridge port 84 | # - Bond slave 85 | # - Ethernet (VLAN) 86 | # 87 | # And for Debian, this one: 88 | # 89 | # - Ethernet (non VLAN) 90 | # - Bond slave 91 | # - Bond master 92 | # - Bridge port (non VLAN) 93 | # - Bridge 94 | # - Bridge port (VLAN) 95 | # - Ethernet (VLAN) 96 | # 97 | # Also, use nohup to ensure the process survives termination of the SSH 98 | # connection. 99 | # 100 | # Note on "--allow" flag for Debian systems: 101 | # 102 | # On Debian system the "--allow" flag to "ifup/ifdown" behaves like a filter 103 | # to the interfaces configured in /etc/network/interfaces. On Debian you 104 | # cannot bounce an interface marked with "allow-hotplug" (e.g. a hot-pluggable 105 | # wifi interface) using "ifup/ifdown", it will fail. Adding the "--allow auto" 106 | # argument to "ifup/ifdown" will only be effective for interfaces marked with 107 | # "auto". Interfaces marked with "allow-hotplug" will simply be ignored then. 108 | # 109 | # Note on Network Manager Bounce mechanism: 110 | # 111 | # 'nmcli connection up' works asynchronously so we need to check if interfaces 112 | # are truly up, as gathering facts in next step would fail due to inactive 113 | # state. Running another loop to check that. 114 | # Dummy interfaces can have UNKNOWN state. 115 | 116 | - name: Bounce networkmanager devices 117 | become: true 118 | command: > 119 | nohup bash -c " 120 | nmcli connection reload; 121 | 122 | returncode=0 123 | {% for interface in all_interfaces_changed | reverse %} 124 | nmcli connection down {{ interface }}; 125 | {% endfor %} 126 | 127 | {% for interface in all_interfaces_changed %} 128 | if ! nmcli connection up {{ interface }}; then 129 | echo \"Failed to bring up interface {{ interface }}\"; 130 | {% if interfaces_bounce_ignore_errors | bool %} 131 | returncode=1 132 | {% endif %} 133 | fi; 134 | {% endfor %} 135 | 136 | echo 'Waiting for interfaces to become active and have a connected carrier'; 137 | for i in {1..20}; do 138 | all_connected=true 139 | {% for interface in all_interfaces_changed %} 140 | if [[ '{{ interface }}' == *dummy* ]]; then 141 | allowed_states='UNKNOWN|UP' 142 | elif [[ '{{ interface }}' == 'lo' ]]; then 143 | allowed_states='UNKNOWN' 144 | else 145 | allowed_states='UP' 146 | fi 147 | 148 | if ! (nmcli -t -f DEVICE,STATE device status | grep -q -w '{{ interface }}:connected' && ip link show '{{ interface }}' | grep -q -E 'state ('$allowed_states')'); then 149 | all_connected=false 150 | if [ $i -eq 20 ]; then 151 | echo 'Interface {{ interface }} failed to become active and have a connected carrier'; 152 | {% if interfaces_bounce_ignore_errors | bool %} 153 | returncode=1 154 | {% endif %} 155 | fi 156 | fi; 157 | {% endfor %} 158 | 159 | if $all_connected; then 160 | break; 161 | fi 162 | sleep 2; 163 | done 164 | 165 | exit $returncode" 166 | vars: 167 | ether_vlan_interfaces_changed: > 168 | {{ ether_interfaces_changed | select('match', vlan_interface_regex) | list}} 169 | ether_non_vlan_interfaces_changed: > 170 | {{ ether_interfaces_changed | reject('match', vlan_interface_regex) | list }} 171 | bridge_port_vlan_interfaces_changed: > 172 | {{ bridge_port_interfaces_changed | select('match', vlan_interface_regex) | list}} 173 | bridge_port_non_vlan_interfaces_changed: > 174 | {{ bridge_port_interfaces_changed | reject('match', vlan_interface_regex) | list }} 175 | all_interfaces_changed: > 176 | {{ ether_non_vlan_interfaces_changed + 177 | bridge_interfaces_changed + 178 | bond_master_interfaces_changed + 179 | bridge_port_interfaces_changed + 180 | bond_slave_interfaces_changed + 181 | ether_vlan_interfaces_changed }} 182 | listen: Bounce network devices 183 | when: interfaces_use_networkmanager 184 | notify: 185 | - Gather facts 186 | - Check active Ethernet interface state 187 | - Check active bond interface state 188 | - Check active bridge interface state 189 | 190 | # The order handlers execute are based on the order they're arranged here. 191 | # We want to do a controlled bounce of interfaces before we do any restart. 192 | - name: Restart NetworkManager 193 | become: true 194 | service: 195 | name: NetworkManager 196 | state: restarted 197 | 198 | # The Reload handler is intentionally placed after Restart so that we do not 199 | # attempt to reload configuration when a full restart is required. In that 200 | # scenario, this handler becomes a no-op as the Restart handler will have 201 | # already applied the changes. If no restart is required, then we can perform 202 | # a less disruptive reload only. 203 | - name: Reload NetworkManager 204 | become: true 205 | service: 206 | name: NetworkManager 207 | state: reloaded 208 | 209 | - name: Bounce network devices 210 | become: true 211 | command: > 212 | nohup bash -c " 213 | returncode=0 214 | {% for interface in all_interfaces_changed | reverse %} 215 | ifdown {% if ansible_facts.os_family == 'Debian' %}--allow auto {% endif %}{{ interface }}; 216 | {% endfor %} 217 | 218 | {% for interface in all_interfaces_changed %} 219 | if ! ifup {% if ansible_facts.os_family == 'Debian' %}--allow auto {% endif %}{{ interface }}; then 220 | echo \"Failed to bring up interface {{ interface }}\"; 221 | {% if interfaces_bounce_ignore_errors | bool %} 222 | returncode=1 223 | {% endif %} 224 | fi; 225 | {% endfor %} 226 | 227 | exit $returncode" 228 | vars: 229 | ether_vlan_interfaces_changed: > 230 | {{ ether_interfaces_changed | select('match', vlan_interface_regex) | list}} 231 | ether_non_vlan_interfaces_changed: > 232 | {{ ether_interfaces_changed | reject('match', vlan_interface_regex) | list }} 233 | bridge_port_vlan_interfaces_changed: > 234 | {{ bridge_port_interfaces_changed | select('match', vlan_interface_regex) | list}} 235 | bridge_port_non_vlan_interfaces_changed: > 236 | {{ bridge_port_interfaces_changed | reject('match', vlan_interface_regex) | list }} 237 | all_interfaces_changed_map: 238 | Debian: > 239 | {{ ether_non_vlan_interfaces_changed + 240 | bond_slave_interfaces_changed + 241 | bond_master_interfaces_changed + 242 | bridge_port_non_vlan_interfaces_changed + 243 | bridge_interfaces_changed + 244 | bridge_port_vlan_interfaces_changed + 245 | ether_vlan_interfaces_changed }} 246 | # On RedHat, bounce any changed bond master interfaces for a second time. 247 | # The reason for this is unclear. 248 | RedHat: > 249 | {{ ether_non_vlan_interfaces_changed + 250 | bridge_interfaces_changed + 251 | bond_master_interfaces_changed + 252 | bridge_port_interfaces_changed + 253 | bond_slave_interfaces_changed + 254 | ether_vlan_interfaces_changed + 255 | bond_master_interfaces_changed }} 256 | all_interfaces_changed: "{{ all_interfaces_changed_map[ansible_facts.os_family] }}" 257 | when: not interfaces_use_networkmanager 258 | notify: 259 | - Pause to wait for interfaces to become active 260 | - Gather facts 261 | - Check active Ethernet interface state 262 | - Check active bond interface state 263 | - Check active bridge interface state 264 | 265 | - name: Pause to wait for interfaces to become active 266 | pause: 267 | seconds: "{{ interfaces_pause_time }}" 268 | 269 | # Update host facts so that we can verify the configuration has been applied 270 | # correctly. 271 | - name: Gather facts 272 | setup: 273 | filter: "{{ interfaces_setup_filter }}" 274 | gather_subset: "{{ interfaces_setup_gather_subset }}" 275 | 276 | - name: Check active Ethernet interface state 277 | fail: 278 | msg: "{{ ether_check.reason }}" 279 | with_items: "{{ interfaces_ether_interfaces }}" 280 | when: ether_check.diff 281 | vars: 282 | ether_check: "{{ item | ether_check }}" 283 | 284 | - name: Check active bond interface state 285 | fail: 286 | msg: "{{ bond_check.reason }}" 287 | with_items: "{{ interfaces_bond_interfaces }}" 288 | when: bond_check.diff 289 | vars: 290 | bond_check: "{{ item | bond_check }}" 291 | 292 | - name: Check active bridge interface state 293 | fail: 294 | msg: "{{ bridge_check.reason }}" 295 | with_items: "{{ interfaces_bridge_interfaces }}" 296 | when: bridge_check.diff 297 | vars: 298 | bridge_check: "{{ item | bridge_check }}" 299 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Ansible Interfaces Role 2 | ======================= 3 | 4 | An ansible role for configuring different network interfaces. 5 | 6 | _WARNING: This role can be dangerous to use. If you lose network connectivity 7 | to your target host by incorrectly configuring your networking, you may be 8 | unable to recover without physical access to the machine._ 9 | 10 | - Ethernet interfaces 11 | - Bridge interfaces 12 | - Bonded interfaces 13 | - Network routes 14 | - IP routing tables 15 | - IP routing rules 16 | 17 | Role Variables 18 | -------------- 19 | 20 | The variables that can be passed to this role and a brief description about 21 | them are as follows: 22 | 23 | ```yaml 24 | # The list of route tables to be defined 25 | interfaces_route_tables: [] 26 | 27 | # The list of ethernet interfaces to be added to the system 28 | interfaces_ether_interfaces: [] 29 | 30 | # The list of bridge interfaces to be added to the system 31 | interfaces_bridge_interfaces: [] 32 | 33 | # The list of bonded interfaces to be added to the system 34 | interfaces_bond_interfaces: [] 35 | 36 | # An optional filter parameter to pass to the setup module. 37 | interfaces_setup_filter: "{{ omit }}" 38 | 39 | # An optional gather_subset parameter to pass to the setup module. 40 | interfaces_setup_gather_subset: "{{ omit }}" 41 | 42 | # An option to merge all configurations setup with merge: true 43 | # in the global interfaces file (Debian-Family only) 44 | interfaces_merge: false 45 | 46 | # An option that does not fail interfaces bounce action when an 47 | # error has occured - useful when you assume one of the interfaces 48 | # to not have proper state. 49 | interfaces_bounce_ignore_errors: false 50 | ``` 51 | 52 | Note: The values for the list are listed in the examples below. 53 | 54 | 1) Configure eth1 and eth2 on a host with a static IP and a dhcp IP. Also 55 | define static routes and a gateway. 56 | 57 | ```yaml 58 | - hosts: myhost 59 | roles: 60 | - role: MichaelRigart.interfaces 61 | interfaces_ether_interfaces: 62 | - device: eth1 63 | bootproto: static 64 | address: 192.168.1.150 65 | netmask: 255.255.255.0 66 | gateway: 192.168.1.1 67 | dnsnameservers: 192.0.2.1 192.0.2.2 68 | dnssearch: example.com 69 | mtu: 9000 70 | pre_up: sleep 5 71 | route: 72 | - network: 192.168.200.0 73 | netmask: 255.255.255.0 74 | gateway: 192.168.1.1 75 | - network: 192.168.100.0 76 | netmask: 255.255.255.0 77 | gateway: 192.168.1.1 78 | - device: eth2 79 | bootproto: dhcp 80 | ``` 81 | 82 | 2) Configure a bridge interface with multiple NICs added to the bridge. 83 | 84 | ```yaml 85 | - hosts: myhost 86 | roles: 87 | - role: MichaelRigart.interfaces 88 | interfaces_bridge_interfaces: 89 | - device: br1 90 | type: bridge 91 | address: 192.168.1.150 92 | netmask: 255.255.255.0 93 | bootproto: static 94 | stp: "on" 95 | mtu: 1500 96 | ports: [eth1, eth2] 97 | ``` 98 | 99 | Note: Routes can also be added for this interface in the same way routes are 100 | added for ethernet interfaces. 101 | 102 | 3) Configure a bond interface with an "active-backup" slave configuration. 103 | 104 | ```yaml 105 | - hosts: myhost 106 | roles: 107 | - role: MichaelRigart.interfaces 108 | interfaces_bond_interfaces: 109 | - device: bond0 110 | mtu: 9000 111 | address: 192.168.1.150 112 | netmask: 255.255.255.0 113 | bootproto: static 114 | bond_mode: active-backup 115 | bond_miimon: 100 116 | bond_slaves: [eth1, eth2] 117 | route: 118 | - network: 192.168.222.0 119 | netmask: 255.255.255.0 120 | gateway: 192.168.1.1 121 | ``` 122 | 123 | 4) Configure a bonded interface with "802.3ad" as the bonding mode, specify the 124 | 802.3ad aggregation selection logic to use the aggregator with largest aggregate 125 | bandwidth, and IP address obtained via DHCP. 126 | 127 | ```yaml 128 | - hosts: myhost 129 | roles: 130 | - role: MichaelRigart.interfaces 131 | interfaces_bond_interfaces: 132 | - device: bond0 133 | bootproto: dhcp 134 | bond_mode: 802.3ad 135 | bond_ad_select: bandwidth 136 | bond_miimon: 100 137 | bond_downdelay: 200 138 | bond_updelay: 200 139 | bond_lacp_rate: 1 140 | bond_xmit_hash_policy: layer3+4 141 | bond_slaves: [eth1, eth2] 142 | ``` 143 | 144 | 5) Configure a routing table `myroutetable`, and an Ethernet interface `eth1` 145 | with an IP routing rule that defines when to use the routing table. It also 146 | configures an IP route on the interface for the `myroutetable` routing table. 147 | 148 | ```yaml 149 | - hosts: myhost 150 | roles: 151 | - role: MichaelRigart.interfaces 152 | interfaces_route_tables: 153 | - name: myroutetable 154 | id: 42 155 | interfaces_ether_interfaces: 156 | - device: eth1 157 | bootproto: static 158 | address: 192.168.1.150 159 | netmask: 255.255.255.0 160 | dnsnameservers: 192.0.2.1 192.0.2.2 161 | dnssearch: example.com 162 | mtu: 9000 163 | route: 164 | - network: 192.168.200.0 165 | netmask: 255.255.255.0 166 | gateway: 192.168.1.1 167 | table: myroutetable 168 | rules: 169 | - from 192.168.200.0/24 table myroutetable 170 | ``` 171 | 172 | 6) Configure a hot-pluggable Wifi interface `wlan0` with a static IP and a 173 | `wpa_supplicant` configuration. Also configure eth0 with a dhcp IP. 174 | 175 | ```yaml 176 | - hosts: myhost 177 | roles: 178 | - role: MichaelRigart.interfaces 179 | interfaces_ether_interfaces: 180 | - device: wlan0 181 | allowclass: allow-hotplug 182 | bootproto: static 183 | address: 192.168.1.150 184 | netmask: 255.255.255.0 185 | network: 192.168.1.0 186 | broadcast: 192.168.1.255 187 | gateway: 192.168.1.1 188 | dnsnameservers: 192.168.1.1 189 | wpaconf: /etc/wpa_supplicant/wpa_supplicant.conf 190 | - device: eth0 191 | bootproto: dhcp 192 | ``` 193 | 194 | 7) Configure a static IPv4 address, route along with an IPv6 address and route on an interface. 195 | 196 | ```yaml 197 | - hosts: myhost 198 | roles: 199 | - role: MichaelRigart.interfaces 200 | interfaces_ether_interfaces: 201 | - device: ens160 202 | bootproto: static 203 | address: 10.99.99.2 204 | netmask: 255.255.255.0 205 | route: 206 | - network: 10.99.98.0 207 | netmask: 255.255.255.0 208 | gateway: 10.99.99.1 209 | ip6: 210 | address: fd49:f9f5:ccb4:2acd::ac18:1002 211 | prefix: 120 212 | route: 213 | - network: 64:FF9B::/96 214 | gateway: fd49:f9f5:ccb4:2acd::ac18:1001 215 | ``` 216 | 217 | 8) All the above examples show how to configure a single host, The below 218 | example shows how to define your network configurations for all your machines. 219 | 220 | Assume your host inventory is as follows: 221 | 222 | ### /etc/ansible/hosts 223 | 224 | [dc1] 225 | host1 226 | host2 227 | 228 | Describe your network configuration for each host in host vars: 229 | 230 | ### host_vars/host1 231 | 232 | ```yaml 233 | interfaces_ether_interfaces: 234 | - device: eth1 235 | bootproto: static 236 | address: 192.168.1.150 237 | netmask: 255.255.255.0 238 | gateway: 192.168.1.1 239 | route: 240 | - network: 192.168.200.0 241 | netmask: 255.255.255.0 242 | gateway: 192.168.1.1 243 | interfaces_bond_interfaces: 244 | - device: bond0 245 | mtu: 9000 246 | bootproto: dhcp 247 | bond_mode: 802.3ad 248 | bond_miimon: 100 249 | bond_slaves: [eth2, eth3] 250 | ``` 251 | 252 | ### host_vars/host2 253 | 254 | ```yaml 255 | interfaces_ether_interfaces: 256 | - device: eth0 257 | bootproto: static 258 | address: 192.168.1.150 259 | netmask: 255.255.255.0 260 | gateway: 192.168.1.1 261 | ``` 262 | 263 | Create a playbook which applies this role to all hosts as shown below, and run 264 | the playbook. All the servers should have their network interfaces configured 265 | and routes updated. 266 | 267 | ```yaml 268 | - hosts: all 269 | roles: 270 | - role: MichaelRigart.interfaces 271 | ``` 272 | 273 | Note: Ansible needs network connectivity throughout the playbook process, you 274 | may need to have a control interface that you do *not* modify using this 275 | method so that Ansible has a stable connection to configure the target 276 | systems. 277 | 278 | 9) CentOS 8 cloud image workaround 279 | 280 | CentOS 8 cloud images ship with ifcfg files for ens3 and eth0. ifcfg-ens3 seems 281 | to be a relic from the image build process, and causes the network service to 282 | fail. ifcfg-eth0 is useful for most virtual machines, but if a cloud image is 283 | deployed on bare metal and eth0 is absent, the network service will fail. This 284 | role will by default remove these files, if there is no such interface on the 285 | system, and no such interface is specified in the role variables. 286 | 287 | This workaround is configured via `interfaces_workaround_centos_remove`. To 288 | set a different interface file to remove: 289 | 290 | ```yaml 291 | interfaces_workaround_centos_remove: 292 | - eth1 293 | ``` 294 | 295 | Or to avoid performing this workaround: 296 | 297 | ```yaml 298 | interfaces_workaround_centos_remove: [] 299 | ``` 300 | 301 | 10) Allowed addresses 302 | 303 | Sometimes it may be useful to not immediately assign an IP address to an 304 | interface, but to allow another process to assign one. An example use case is a 305 | virtual IP address dynamically added or by a process such as keepalived. 306 | This may be configured via an `allowed_addresses` field in an Ethernet, bond or 307 | bridge interface configuration. 308 | 309 | ```yaml 310 | - hosts: myhost 311 | roles: 312 | - role: MichaelRigart.interfaces 313 | interfaces_ether_interfaces: 314 | - device: eth0 315 | bootproto: static 316 | address: 0.0.0.0 317 | allowed_addresses: 318 | - 10.0.0.2 319 | ``` 320 | 321 | 11) Custom options for static routes 322 | 323 | Adding custom options to static routes is possible via the `options` attribute, 324 | which should be a list. 325 | 326 | ```yaml 327 | - hosts: myhost 328 | roles: 329 | - role: MichaelRigart.interfaces 330 | interfaces_ether_interfaces: 331 | - device: eth0 332 | bootproto: static 333 | address: 0.0.0.0 334 | route: 335 | - network: 192.168.200.0 336 | netmask: 255.255.255.0 337 | gateway: 192.168.1.1 338 | options: 339 | - onlink 340 | - metric 400 341 | ``` 342 | 343 | 12) Configure an IPoIB (infiniband) interface 344 | 345 | Configuring an IPoIB interface is possible using `type: ipoib` when defining the interface. 346 | 347 | **WARNING: You can configure the ip address and routes for an IPoIB interface but other functionalities like vlans are not supported in infiniband networks** 348 | 349 | ```yaml 350 | - hosts: myhost 351 | roles: 352 | - role: MichaelRigart.interfaces 353 | interfaces_ether_interfaces: 354 | - device: eth0 355 | bootproto: static 356 | address: 192.168.1.150 357 | netmask: 255.255.255.0 358 | gateway: 192.168.1.1 359 | - device: ib0 360 | bootproto: static 361 | address: 10.10.1.10 362 | netmask: 255.255.255.0 363 | type: ipoib 364 | ``` 365 | 366 | 13) Configure ethtool options (RedHat-family only) 367 | 368 | Setting ethtool options on an interface is possible using the `ethtool_opts` 369 | attribute, which should be a string. For example, this can be used to set RX/TX 370 | ring parameters. This is only supported on distributions of the RedHat family. 371 | 372 | ```yaml 373 | - hosts: myhost 374 | roles: 375 | - role: MichaelRigart.interfaces 376 | interfaces_ether_interfaces: 377 | - device: eth0 378 | bootproto: static 379 | address: 192.168.1.150 380 | netmask: 255.255.255.0 381 | gateway: 192.168.1.1 382 | ethtool_opts: "-G ${DEVICE} rx 8192 tx 8192" 383 | ``` 384 | 385 | To apply ethtool options to bond slaves or bridge ports, set the attribute on 386 | the bond or bridge itself. Setting different options per underlying interface 387 | is not supported at this time. 388 | 389 | 14) Configure firewalld zones (RedHat-family only) 390 | 391 | Adding interface to firewalld zone is possible using the `zone` attribute. 392 | This is only supported on distributions of the RedHat family. 393 | 394 | ```yaml 395 | - hosts: myhost 396 | roles: 397 | - role: MichaelRigart.interfaces 398 | interfaces_ether_interfaces: 399 | - device: eth0 400 | bootproto: static 401 | address: 192.168.1.150 402 | netmask: 255.255.255.0 403 | gateway: 192.168.1.1 404 | zone: trusted 405 | ``` 406 | 407 | 15) Pause to wait for interfaces to become active 408 | 409 | On some OS distributions (including Ubuntu), it may be necessary to wait after 410 | bouncing network interfaces before they are active. This can be done by setting 411 | ``interfaces_pause_time`` to a number of seconds to delay. 412 | 413 | 16) Configure HW(MAC) address for interface 414 | 415 | Configuring interface HW adrress is possible using the `hwaddr` attribute. 416 | This alone may not be sufficient to change MAC from default one, however 417 | specifying hw address is necessary for some systems. 418 | 419 | ```yaml 420 | - hosts: myhost 421 | roles: 422 | - role: MichaelRigart.interfaces 423 | interfaces_ether_interfaces: 424 | - device: eth0 425 | bootproto: static 426 | address: 192.168.1.150 427 | netmask: 255.255.255.0 428 | gateway: 192.168.1.1 429 | hwaddr: 00:11:22:33:44:55 430 | ``` 431 | 432 | 17) Configure HW(MAC) address for bonded/bridged interface 433 | 434 | Configuring interface HW adrress is possible using the `hwaddr` attribute. 435 | 436 | ```yaml 437 | - hosts: myhost 438 | roles: 439 | - role: MichaelRigart.interfaces 440 | interfaces_bond_interfaces: 441 | - device: bond0 442 | bootproto: dhcp 443 | bond_mode: 802.3ad 444 | hwaddr: 00:11:22:33:44:55 445 | interfaces_bridge_interfaces: 446 | - device: br1 447 | type: bridge 448 | bootproto: dhcp 449 | hwaddr: 00:11:22:33:44:66 450 | ports: [eth1, eth2] 451 | ``` 452 | 453 | 18) Routes and rules can be a mix of strings and hashes (a.k.a. dict, mapping, associative array, etc.) allowing 454 | the role to handle rules and routes outside the expected formats. These can also be applied to loopback devices in 455 | distributions using Network Manager's new `nmconnect` configuration files (e.g. RHEL8 & RHEL9). 456 | 457 | The example below configures an interface, to act as a second interface so that any traffic that hits it is returned via the same interface. In addition internal traffic is marked so it can be picked up by some other service (like HAproxy). 458 | 459 | ### host_vars/proxy1 460 | ```yaml 461 | interfaces_route_tables: 462 | - name: frontend 463 | id: 200 464 | - name: marktable 465 | id: 100 466 | interfaces_ether_interfaces: 467 | - device: eth1 468 | bootproto: static 469 | address: 10.10.10.1 470 | netmask: 255.255.255.0 471 | defroute: false 472 | route: 473 | - table: frontend 474 | device: eth1 475 | network: 0.0.0.0 476 | netmask: 0.0.0.0 477 | gateway: 10.10.10.254 478 | rules: 479 | - from: 10.10.10.1 480 | table: frontend 481 | - "fwmark 1 lookup marktable" 482 | - device: lo 483 | type: loopback 484 | # Setting bootproto to dhcp is required to set `method=auto` in the nmconnect file 485 | # This replicates `ip route add local 0.0.0.0/0 dev lo table 100"` 486 | bootproto: dhcp 487 | route: 488 | - table: marktable 489 | device: lo 490 | network: 0.0.0.0 491 | netmask: 0 492 | options: 493 | - type: local 494 | ``` 495 | 496 | Example Playbook 497 | ---------------- 498 | 499 | ```yaml 500 | - hosts: servers 501 | roles: 502 | - { role: MichaelRigart.interfaces, become: true } 503 | ``` 504 | License 505 | ------- 506 | 507 | GPLv3 508 | 509 | Author Information 510 | ------------------ 511 | 512 | Michaël Rigart 513 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . --------------------------------------------------------------------------------