Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
75b0c7f
Allowing arbitrary options
chmduquesne Feb 28, 2018
17e0e62
moving from 'auto' to 'triggers'
chmduquesne Feb 28, 2018
fbdac40
Changing default auto
chmduquesne Feb 28, 2018
480f364
--diff in travis build
chmduquesne Feb 28, 2018
199093b
excluding triggers in options
chmduquesne Feb 28, 2018
602fe78
Further filtering special keys
chmduquesne Feb 28, 2018
78e6a14
Removing subnets and dns servers, updating doc
chmduquesne Feb 28, 2018
ad34d36
Adding author
chmduquesne Feb 28, 2018
010185b
Readding the original notifications for travis
chmduquesne Feb 28, 2018
1728e09
correcting list filter
chmduquesne Feb 28, 2018
3c9e816
typo item -> key
chmduquesne Feb 28, 2018
56aadb7
if no trigger is provided, the default should be 'auto'
chmduquesne Feb 28, 2018
b4cb0a7
typo misplaced else
chmduquesne Feb 28, 2018
f2d012a
Hard fork
chmduquesne Mar 1, 2018
49710bd
Add post-up and pre-down keyword
Mar 13, 2018
039cb45
Add post-up and pre-down into README.md
Mar 13, 2018
acfee73
Merge pull request #1 from dubiety/master
chmduquesne Mar 13, 2018
692879a
Sorting keys to get a predictible order
chmduquesne Oct 24, 2018
a99cfaa
updating tests so that they are the same on vagrant and travis
chmduquesne Oct 24, 2018
01d487f
making the test more travis friendly
chmduquesne Oct 24, 2018
915f9f8
gaining 2 seconds
chmduquesne Oct 24, 2018
85f1ce3
trying static approach
chmduquesne Oct 24, 2018
e6a5a3b
testing different kind of triggers
chmduquesne Oct 24, 2018
e5bdaf4
Adding missing versions of ansible
chmduquesne Oct 24, 2018
c81b9a5
Removing support for old versions of ansible
chmduquesne Oct 24, 2018
de26d7f
Role name to please galaxy
chmduquesne Jan 11, 2019
cdfdf13
Fixing badges
chmduquesne Jan 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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.
- >
Expand All @@ -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
58 changes: 34 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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}.<arbitrary_option>`: Additional arbitrary option to the interface

##### Bridge

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
5 changes: 4 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
3 changes: 2 additions & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
36 changes: 12 additions & 24 deletions templates/etc/network/interfaces.d/device.j2
Original file line number Diff line number Diff line change
@@ -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 -%}

Expand All @@ -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 }}
Expand Down
13 changes: 13 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
6 changes: 4 additions & 2 deletions tests/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }}"
Expand Down