Skip to content

Commit 8ce46ba

Browse files
authored
Merge pull request #7 from Oefenweb/consistency-changes
Consistency changes
2 parents 9939cb7 + 573a625 commit 8ce46ba

File tree

6 files changed

+25
-24
lines changed

6 files changed

+25
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## network-interfaces
22

3-
[![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/list#/roles/5783)
3+
[![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)
44

55
Manage network interfaces in Debian-like systems.
66

Vagrantfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ boxes = [
1818
:cpu => "50",
1919
:ram => "256"
2020
},
21+
{
22+
:name => "ubuntu-1604",
23+
:box => "bento/ubuntu-16.04",
24+
:ip => '10.0.0.13',
25+
:cpu => "50",
26+
:ram => "256"
27+
},
2128
{
2229
:name => "debian-711",
2330
:box => "bento/debian-7.11",

defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
network_interfaces_manage_devices: true
44

55
network_interfaces_interfaces:
6-
- device: eth0
6+
- device: "{{ ansible_default_ipv4['interface'] }}"
77
auto: true
88
family: inet
99
method: dhcp

meta/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ galaxy_info:
1111
versions:
1212
- precise
1313
- trusty
14+
- xenial
1415
- name: Debian
1516
versions:
1617
- wheezy

tasks/main.yml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
- network-interfaces-all-interfaces
2323

2424
- name: list network interfaces
25-
command: "find {{ network_interfaces_interface_path }} -type f"
25+
command: find {{ network_interfaces_interface_path }} -type f
2626
changed_when: false
2727
when: network_interfaces_interfaces | length > 0
28-
register: network_interfaces_existing_files
28+
register: _network_interfaces_existing_files
2929
tags:
3030
- configuration
3131
- network-interfaces
@@ -35,8 +35,8 @@
3535
template:
3636
src: etc/network/interfaces.d/device.j2
3737
dest: "{{ network_interfaces_interface_path }}/device-{{ item.device }}-{{ item.family | default('inet') }}"
38-
with_items: network_interfaces_interfaces
39-
register: network_interfaces_configuration_result
38+
with_items: "{{ network_interfaces_interfaces }}"
39+
register: _network_interfaces_configuration_result
4040
tags:
4141
- configuration
4242
- network-interfaces
@@ -45,9 +45,8 @@
4545
- name: configured files
4646
set_fact:
4747
network_interfaces_configured_files: >
48-
[{% for item in network_interfaces_configuration_result.results | default([]) -%}
49-
u"{{ item.dest | default(item.path) }}"
50-
{{ '' if loop.last else ',' }}
48+
[{% for item in _network_interfaces_configuration_result.results | default([]) -%}
49+
{{ item.dest | default(item.path) | string }}{{ '' if loop.last else ',' }}
5150
{%- endfor %}]
5251
tags:
5352
- configuration
@@ -58,10 +57,8 @@
5857
file:
5958
path: "{{ item }}"
6059
state: absent
61-
when: >
62-
network_interfaces_manage_devices
63-
and (item not in network_interfaces_configured_files)
64-
with_items: network_interfaces_existing_files.stdout_lines | default([])
60+
when: network_interfaces_manage_devices and (item not in network_interfaces_configured_files)
61+
with_items: "{{ _network_interfaces_existing_files.stdout_lines | default([]) }}"
6562
tags:
6663
- configuration
6764
- network-interfaces
@@ -71,13 +68,9 @@
7168
service:
7269
name: "{{ network_interfaces_service }}"
7370
state: restarted
74-
arguments: "INTERFACE={{ item.0 }}"
75-
when: >
76-
(0 != item.1 | selectattr('changed') | list | length)
77-
and ((0 != item.1 | selectattr('item.auto', 'undefined') | list | length)
78-
or (true in item.1 | selectattr('item.auto') | list)
79-
)
80-
with_items: network_interfaces_configuration_result.results | default([]) | groupby('item.device')
71+
arguments: "INTERFACE={{ item.item.device }}"
72+
when: item.changed and item.item.auto | default(true)
73+
with_items: "{{ _network_interfaces_configuration_result.results | default([]) }}"
8174
tags:
8275
- configuration
8376
- network-interfaces

tests/vagrant.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
vars:
99
network_interfaces_manage_devices: true
1010
network_interfaces_interfaces:
11-
- device: eth0
11+
- device: "{{ hostvars[inventory_hostname]['ansible_' + (ansible_interfaces | difference(['lo']) | sort | list | first)]['device'] }}"
1212
auto: true
1313
family: inet
1414
method: dhcp
1515
pre-up:
1616
- 'sleep 2'
17-
- device: eth1
17+
- device: "{{ hostvars[inventory_hostname]['ansible_' + (ansible_interfaces | difference(['lo']) | sort | list | last)]['device'] }}"
1818
auto: true
1919
family: inet
2020
method: static
21-
address: "{{ ansible_eth1.ipv4.address }}"
22-
netmask: "{{ ansible_eth1.ipv4.netmask }}"
21+
address: "{{ hostvars[inventory_hostname]['ansible_' + (ansible_interfaces | difference(['lo']) | sort | list | last)]['ipv4']['address'] }}"
22+
netmask: "{{ hostvars[inventory_hostname]['ansible_' + (ansible_interfaces | difference(['lo']) | sort | list | last)]['ipv4']['netmask'] }}"

0 commit comments

Comments
 (0)