diff --git a/.travis.yml b/.travis.yml index a84d900..bfe8470 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,26 @@ python: "2.7" env: - ANSIBLE_VERSION=latest + - ANSIBLE_VERSION=2.7.0 + - ANSIBLE_VERSION=2.6.5 + - ANSIBLE_VERSION=2.6.4 + - ANSIBLE_VERSION=2.6.3 + - ANSIBLE_VERSION=2.6.2 + - ANSIBLE_VERSION=2.6.1 + - ANSIBLE_VERSION=2.6.0 + - ANSIBLE_VERSION=2.5.9 + - ANSIBLE_VERSION=2.5.8 + - ANSIBLE_VERSION=2.5.7 + - ANSIBLE_VERSION=2.5.6 + - ANSIBLE_VERSION=2.5.5 + - ANSIBLE_VERSION=2.5.4 + - ANSIBLE_VERSION=2.5.3 + - ANSIBLE_VERSION=2.5.2 + - ANSIBLE_VERSION=2.5.1 + - ANSIBLE_VERSION=2.5.0 + - ANSIBLE_VERSION=2.4.6.0 + - ANSIBLE_VERSION=2.4.5.0 + - ANSIBLE_VERSION=2.4.4.0 - ANSIBLE_VERSION=2.4.3.0 - ANSIBLE_VERSION=2.4.2.0 - ANSIBLE_VERSION=2.4.1.0 @@ -19,18 +39,6 @@ env: - ANSIBLE_VERSION=2.2.2.0 - ANSIBLE_VERSION=2.2.1.0 - ANSIBLE_VERSION=2.2.0.0 - - ANSIBLE_VERSION=2.1.6 - - ANSIBLE_VERSION=2.1.5 - - ANSIBLE_VERSION=2.1.4 - - ANSIBLE_VERSION=2.1.3 - - ANSIBLE_VERSION=2.1.2 - - ANSIBLE_VERSION=2.1.1.0 - - ANSIBLE_VERSION=2.1.0.0 - - ANSIBLE_VERSION=2.0.2.0 - - ANSIBLE_VERSION=2.0.1.0 - - ANSIBLE_VERSION=2.0.0.2 - - ANSIBLE_VERSION=2.0.0.1 - - ANSIBLE_VERSION=2.0.0.0 branches: only: @@ -49,7 +57,7 @@ script: - ansible-playbook -i tests/inventory tests/test.yml --syntax-check # Run the role/playbook with ansible-playbook. - - ansible-playbook -i tests/inventory tests/test.yml -vvvv + - ansible-playbook -i tests/inventory tests/test.yml -vvvv --diff # Run the role/playbook again, checking to make sure it's idempotent. - > @@ -61,8 +69,4 @@ script: - if [ "$ANSIBLE_VERSION" = "latest" ]; then ansible-lint tests/test.yml || true; fi notifications: - email: false - hipchat: - rooms: - secure: ATB7pOOYjfsPaCfpZEbkmPDdX0Me0fy4ORCBe6bPdu5l7IlohXKRGm52fxU74tlQ5SBviwChz4gTcVkNiCY4i21ZLG6dmj8feBpNq+WFIvJmZyvmp0eqIPuTgskxOu3TKzTTyJXRhSZFOB0Kikl3OmEGx0g2DTf74kcl3LTRfZGYDzGUlyaM5HGeXZRVxDjAQnlNQiqjgKaD6B78mh0/BCHQmi5Ue+GyQSVtXdzNkoKeitdaukwqNjJCEyNtKjMRjPB6R0gY1lRADjTUe5lWvWO7HT+4e7n9pSlk30aQTnicWJJO7fq0ZKTcOY30eyA/hvHDxoJtW+24TX806WTM9XtiiBxv+PBfBKLIZyzhxBQWdVZgF+77PeMLqwnwe+kbDawaBQosrz/8vZ6kuI2UX2b43sI4ag1T8Lur/ddbGoQNLHIvlFH/QxMOZtBM0W2IQhtz9aKO6Z/pZURWxN6ebqgf6LsP01DQBCRR8rMs7GI++f8Eu4NQtzBROWnvRsOuQ2BtUQe5QL7dgfrFRfZZfjfJODrgOCkiANl9l5VglHV0RojScRP79JccZ+JM9uVEmqGDkBfTjSIm9e9Gcm9PC/gfxiXq0Wh16WSzYvvqhYIzCRnrakp6Tyy90BzW6W6QQRirsxvzPSLc7Wic1oKahZlme2cUzmE6Pd/j8xH5VwM= - webhooks: https://galaxy.ansible.com/api/v1/notifications/ + email: true diff --git a/README.md b/README.md index 5d5f7fc..dcb6e01 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ ## network-interfaces -[![Build Status](https://travis-ci.org/Oefenweb/ansible-network-interfaces.svg?branch=master)](https://travis-ci.org/Oefenweb/ansible-network-interfaces) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-network--interfaces-blue.svg)](https://galaxy.ansible.com/tersmitten/network-interfaces) +[![Build Status](https://travis-ci.org/chmduquesne/ansible-network-interfaces.svg?branch=master)](https://travis-ci.org/chmduquesne/ansible-network-interfaces) +[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-chmduquesne.network_interfaces-blue.svg)](https://galaxy.ansible.com/chmduquesne/network_interfaces) Manage network interfaces in Debian-like systems. @@ -15,20 +16,10 @@ None * `network_interfaces_manage_devices`: [required]: Whether all additional scripts should be deleted * `network_interfaces_interfaces`: [default: `[]`]: Network interfaces declarations * `network_interfaces_interfaces.{n}.device`: [required]: Device name -* `network_interfaces_interfaces.{n}.auto`: [default: `true`]: Enable on boot +* `network_interfaces_interfaces.{n}.triggers`: [default: `['auto']`]: When to enable|disable the interface * `network_interfaces_interfaces.{n}.family`: [default: `inet`]: Network type, eg. inet | inet6 * `network_interfaces_interfaces.{n}.method`: [default: `dhcp`]: Method of the interface, eg. dhcp | static - -* `network_interfaces_interfaces.{n}.address`: [optional]: Address -* `network_interfaces_interfaces.{n}.network`: [optional]: Network address -* `network_interfaces_interfaces.{n}.netmask`: [optional]: Netmask -* `network_interfaces_interfaces.{n}.broadcast`: [optional]: Broadcast address -* `network_interfaces_interfaces.{n}.gateway`: [optional]: Default gateway -* `network_interfaces_interfaces.{n}.nameservers`: [optional]: List of nameservers for this interface -* `network_interfaces_interfaces.{n}.dns_search`: [optional]: Search list for host-name lookup -* `network_interfaces_interfaces.{n}.mtu`: [optional]: MTU of the interface - -* `network_interfaces_interfaces.{n}.subnets`: [optional]: List of additional subnets, eg. ['192.168.123.0/24', '192.168.124.11/32'] +* `network_interfaces_interfaces.{n}.`: Additional arbitrary option to the interface ##### Bridge @@ -37,12 +28,14 @@ None * `network_interfaces_interfaces.{n}.bridge.stp`: [optional]: Turn spanning tree protocol on/off * `network_interfaces_interfaces.{n}.bridge.fd`: [optional]: Bridge forward delay * `network_interfaces_interfaces.{n}.bridge.maxwait`: [optional]: Maximum time to wait for the bridge ports to get to the forwarding status -* `network_interfaces_interfaces.{n}.bridge.waitport`: [optional]: Maximum time to wait for the specified ports to become available +* `network_interfaces_interfaces.{n}.bridge.waitport`: [optional]: Maximum time to wait for the specified ports to become available ##### Inline hook scripts * `network_interfaces_interfaces.{n}.pre-up`: [optional, default: `[]`]: List of pre-up script lines * `network_interfaces_interfaces.{n}.up`: [optional, default: `[]`]: List of up script lines +* `network_interfaces_interfaces.{n}.post-up`: [optional, default: `[]`]: List of post-up script lines +* `network_interfaces_interfaces.{n}.pre-down`: [optional, default: `[]`]: List of pre-down script lines * `network_interfaces_interfaces.{n}.down`: [optional, default: `[]`]: List of down script lines * `network_interfaces_interfaces.{n}.post-down`: [optional, default: `[]`]: List of post-down script lines @@ -53,31 +46,51 @@ None #### Example(s) +##### Online.net Dedibox with dedicated ipv6 block + +```yaml +# Assuming dhclient is configured with the right client id +- hosts: dedibox + roles: + - chmduquesne.ansible-network-interfaces + vars: + network_interfaces_manage_devices: true + network_interfaces_interfaces: + - device: enp0s20 + family: inet + method: dhcp + - device: enp0s20 + family: inet6 + method: dhcp + request_prefix: 1 + up: + - "ip addr add {{ vault_inet6_address }}/{{ vault_inet6_netmask }} dev $IFACE" +``` + + ##### DigitalOcean droplet with private networking enabled ```yaml --- - hosts: all roles: - - network-interfaces + - chmduquesne.ansible-network-interfaces vars: network_interfaces_manage_devices: true network_interfaces_interfaces: - device: eth0 - auto: true + triggers: ['auto'] family: inet method: static address: 188.166.9.28 netmask: 255.255.0.0 gateway: 188.166.0.1 mtu: 1500 - nameservers: - - 8.8.8.8 - - 8.8.4.4 + dns-nameservers: "8.8.8.8 8.8.4.4" up: - 'ip addr add 10.18.0.8/16 dev eth0' - device: eth1 - auto: true + triggers: ['auto'] family: inet method: static address: 10.133.136.172 @@ -93,7 +106,4 @@ MIT * Andreas Reischuck * Mark van Driel * Mischa ter Smitten - -#### Feedback, bug-reports, requests, ... - -Are [welcome](https://github.com/Oefenweb/ansible-network-interfaces/issues)! +* Christophe-Marie Duquesne diff --git a/defaults/main.yml b/defaults/main.yml index 97b4d1f..eb78686 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -4,10 +4,13 @@ network_interfaces_manage_devices: true network_interfaces_interfaces: - device: "{{ ansible_default_ipv4['interface'] }}" - auto: true + triggers: + - auto family: inet method: dhcp pre-up: [] up: [] + post-up: [] + pre-down: [] down: [] post-down: [] diff --git a/meta/main.yml b/meta/main.yml index 5e4fcec..c9176ef 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,11 +1,12 @@ # meta file for network-interfaces --- galaxy_info: + role_name: network_interfaces author: Andreas Reischuck company: Dresden Weekly description: Manage network interfaces in Debian-like systems license: MIT - min_ansible_version: 2.0.0.0 + min_ansible_version: 2.2.0.0 platforms: - name: Ubuntu versions: diff --git a/templates/etc/network/interfaces.d/device.j2 b/templates/etc/network/interfaces.d/device.j2 index fe0bd8e..af7b079 100644 --- a/templates/etc/network/interfaces.d/device.j2 +++ b/templates/etc/network/interfaces.d/device.j2 @@ -1,23 +1,20 @@ # {{ ansible_managed }} -{% if item.auto | default(true) %} +{% set special_keys = ['triggers', 'device', 'family', 'method', 'bridge', 'pre-up', 'up', 'post-up', 'pre-down', 'down', 'post-down']%} + +{%- if item.triggers is defined -%} +{% for trigger in item.triggers %} +{{ trigger }} {{ item.device }} +{% endfor %} +{% else %} auto {{ item.device }} {% endif %} iface {{ item.device }} {{ item.family | default('inet', true) }} {{ item.method | default('dhcp', true) }} -{% for key in ['address', 'network', 'netmask', 'broadcast', 'gateway'] %} -{% if key in item %} +{% for key in item.keys() | sort %} +{% if key not in special_keys %} {{ key }} {{ item[key] }} -{% endif %} -{% endfor %} -{%- if item.nameservers is defined %} - dns-nameservers {{ item.nameservers | join(' ') }} -{% endif %} -{%- if item.dns_search is defined %} - dns-search {{ item.dns_search }} -{% endif %} -{%- if item.mtu is defined %} - mtu {{ item.mtu }} {% endif %} +{% endfor %} {%- if item.bridge is defined -%} @@ -29,19 +26,10 @@ iface {{ item.device }} {{ item.family | default('inet', true) }} {{ item.method {% endfor %} {% endif %} -{%- if item.subnets is defined %} - - # additional subnets -{% for subnet in item.subnets %} - up /sbin/ip addr add {{ subnet }} dev {{ item.device }} - down /sbin/ip addr del {{ subnet }} dev {{ item.device }} -{% endfor %} -{% endif %} - -{%- if ['pre-up', 'up', 'down', 'post-down'] | intersect(item.keys()) %} +{%- if ['pre-up', 'up', 'post-up', 'pre-down', 'down', 'post-down'] | intersect(item.keys()) %} # hook scripts -{% for key in ['pre-up', 'up', 'down', 'post-down'] %} +{% for key in ['pre-up', 'up', 'post-up', 'pre-down', 'down', 'post-down'] %} {% if key in item %} {% for value in item[key] %} {{ key }} {{ value }} diff --git a/tests/test.yml b/tests/test.yml index c889f41..48dc4b3 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -5,3 +5,16 @@ become: true roles: - ../../ + vars: + network_interfaces_manage_devices: true + network_interfaces_interfaces: + - device: "{{ hostvars[inventory_hostname]['ansible_' + (ansible_interfaces | difference(['lo']) | sort | list | first)]['device'] }}" + triggers: + - allow-hotplug + - auto + family: inet + method: static + address: "{{ hostvars[inventory_hostname]['ansible_' + (ansible_interfaces | difference(['lo']) | sort | list | first)]['ipv4']['address'] }}" + netmask: "{{ hostvars[inventory_hostname]['ansible_' + (ansible_interfaces | difference(['lo']) | sort | list | first)]['ipv4']['netmask'] }}" + pre-up: + - 'true' diff --git a/tests/vagrant.yml b/tests/vagrant.yml index a257108..ae1bdb3 100644 --- a/tests/vagrant.yml +++ b/tests/vagrant.yml @@ -9,13 +9,15 @@ network_interfaces_manage_devices: true network_interfaces_interfaces: - device: "{{ hostvars[inventory_hostname]['ansible_' + (ansible_interfaces | difference(['lo']) | sort | list | first)]['device'] }}" - auto: true + triggers: + - auto family: inet method: dhcp pre-up: - 'sleep 2' - device: "{{ hostvars[inventory_hostname]['ansible_' + (ansible_interfaces | difference(['lo']) | sort | list | last)]['device'] }}" - auto: true + triggers: + - auto family: inet method: static address: "{{ hostvars[inventory_hostname]['ansible_' + (ansible_interfaces | difference(['lo']) | sort | list | last)]['ipv4']['address'] }}"