-
Notifications
You must be signed in to change notification settings - Fork 61
/
device.j2
95 lines (79 loc) · 2.75 KB
/
device.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# {{ ansible_managed }}
{# schema: item = [ <device>, [<config>, ...] ] #}
{% for config in item.1 %}
{% if config.auto | default(loop.first) %}
auto {{ config.device }}
{% endif %}
{% for stanza in config.allow | default([]) %}
allow-{{ stanza }}
{% endfor %}
iface {{ config.device }} {{ config.family | default('inet', true) }} {{ config.method | default('dhcp', true) }}
{% set iface_keys = ['description', 'address', 'broadcast', 'gateway', 'netmask', 'network', 'mtu', 'metric', 'pointopoint'] %}
{% for key in iface_keys %}
{% if key in config %}
{{ key }} {{ config[key] }}
{% endif %}
{% endfor -%}
{% if config['additional_options'] is defined %}
{% for key, value in config['additional_options'].items() | sort %}
{{ key }} {{ value }}
{% endfor %}
{% endif %}
{# nameservers #}
{%- if (config.nameservers is defined) and (0 < config.nameservers | length) %}
dns-nameservers {{ config.nameservers | join(' ') }}
{% endif %}
{%- if config.dns_search is defined %}
dns-search {{ config.dns_search }}
{% endif -%}
{# subnets #}
{%- if (config.subnets is defined) and (0 < config.subnets | length) %}
# additional subnets
{% for subnet in config.subnets %}
up /sbin/ip addr add {{ subnet }} dev {{ config.device }}
down /sbin/ip addr del {{ subnet }} dev {{ config.device }}
{% endfor %}
{% endif -%}
{# bridge settings #}
{%- set bridge_keys = ['ports', 'stp', 'fd', 'maxwait', 'waitport'] %}
{% if (config.bridge is defined) and (bridge_keys | intersect(config.bridge.keys())) -%}
# bridge settings
{% for key in bridge_keys %}
{% if key in config.bridge -%}
bridge_{{ key }} {{ config.bridge[key] }}
{% endif %}
{% endfor %}
{% endif -%}
{# bond parameters #}
{%- set bond_keys = ['mode', 'miimon', 'master', 'slaves', 'lacp-rate', 'xmit-hash-policy'] %}
{% if (config.bond is defined) and (bond_keys | intersect(config.bond.keys())) -%}
# bond parameters
{% for key in bond_keys %}
{% if key in config.bond -%}
bond-{{ key }} {{ config.bond[key] }}
{% endif %}
{% endfor %}
{% endif -%}
{# vlan #}
{%- set vlan_keys = ['raw-device'] %}
{% if (config.vlan is defined) and (vlan_keys | intersect(config.vlan.keys())) -%}
# vlan
{% for key in vlan_keys %}
{% if key in config.vlan %}
vlan-{{ key }} {{ config.vlan[key] }}
{% endif %}
{% endfor %}
{% endif -%}
{# hook scripts #}
{%- set hook_keys = ['pre-up', 'up', 'post-up', 'pre-down', 'down', 'post-down'] %}
{% if hook_keys | intersect(config.keys()) %}
# hook scripts
{% for key in hook_keys %}
{% if key in config %}
{% for value in config[key] %}
{{ key }} {{ value }}
{% endfor %}
{% endif %}
{% endfor %}
{% endif -%}
{% endfor %}