-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit uses the new configuration format. Among other things, this allows for multiple subnets, syncing between devices, and accounts for CARP. This refactor includes work from @the-maldridge
- Loading branch information
Showing
4 changed files
with
68 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
dependencies: | ||
- { role: sg-base } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
dhcpd_flags="{{ sg_network|selectattr('services', 'issuperset', ['dhcp'])|list|map(attribute='name')|join(' ') }}" | ||
dhcpd_flags="{% if sg_globalconf.dhcp is defined and sg_globalconf.dhcp.synctarget is defined and sg_globalconf.dhcp.synclisten is defined %} | ||
-Y {{ sg_globalconf.dhcp.synctarget }} -y {{ sg_globalconf.dhcp.synclisten }} {% endif %} | ||
-A baddhcp -C activedhcp -L activedhcp {% for interface in sg_interfaces %} | ||
{% if interface.carpdev is not defined %} | ||
{% set real_interfaces = sg_interfaces|json_query('[?carpdev==\''+interface.name+'\'].name')|list + [interface.name] %} | ||
{% set dhcp_networks = [] %} | ||
{% for network in sg_networks|selectattr('services', 'issuperset', ['dhcp'])|list %} | ||
{% if network.attach_to in real_interfaces %} | ||
{% if dhcp_networks.append(network) %}{% endif %} | ||
{% endif %} | ||
{% endfor %} | ||
{% if dhcp_networks %}{{ interface.name }}{% endif %} | ||
{% endif %} | ||
{% endfor %}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,63 @@ | ||
#jinja2: trim_blocks: "true", lstrip_blocks: "true" | ||
authoritative; | ||
|
||
{% for interface in sg_network %} | ||
{% if "dhcp" in interface.services %} | ||
{% set dhcpconf = interface.serviceconf.dhcp %} | ||
subnet {{ interface.cidr | ipaddr('network') }} netmask {{ interface.cidr | ipaddr('netmask') }} { | ||
range {{ dhcpconf.pool | ipaddr('1') | ipaddr('address') }} {{ dhcpconf.pool | ipaddr('-2') | ipaddr('address') }}; | ||
default-lease-time {{ dhcpconf.default_lease_time | default(3600) }}; | ||
max-lease-time {{ dhcpconf.max_lease_time | default(7200) }}; | ||
option routers {{ dhcpconf.routers | default(interface.address) }}; | ||
option domain-name "{{ interface.domain | default(sg_globalconf.domain) }}"; | ||
option domain-name-servers {{ dhcpconf.dns | default(interface.address) }}; | ||
option ntp-servers {{ dhcpconf.ntp | default(interface.address) }}; | ||
{% if dhcpconf.pxeboot_fname is defined %} | ||
filename "{{ dhcpconf.pxeboot_fname }}"; | ||
next-server {{ dhcpconf.pxeboot_next | default(interface.address) }}; | ||
{% for interface in sg_interfaces %} | ||
{% if interface.carpdev is not defined %} | ||
{% set real_interfaces = sg_interfaces|json_query('[?carpdev==\''+interface.name+'\'].name')|list + [interface.name] %} | ||
{% set dhcp_networks = [] %} | ||
{% for network in sg_networks|selectattr('services', 'issuperset', ['dhcp'])|list %} | ||
{% if network.attach_to in real_interfaces %} | ||
{% if dhcp_networks.append(network) %}{% endif %} | ||
{% endif %} | ||
} | ||
|
||
group { | ||
# Gateway Interface | ||
host {{ sg_globalconf.hostname }} { | ||
hardware ethernet {{ hostvars[inventory_hostname]['ansible_' + interface.name]['macaddress'] }}; | ||
fixed-address {{ interface.address }}; | ||
{% endfor %} | ||
{% if dhcp_networks|length >1 %} | ||
shared-network {{ interface.name }} { | ||
{% endif %} | ||
{% for network in dhcp_networks %} | ||
{% set dhcpconf = network.serviceconf.dhcp %} | ||
subnet {{ network.cidr|ipaddr('network') }} netmask {{ network.cidr|ipaddr('netmask') }} { | ||
{% if dhcpconf.pools is defined %} | ||
{% for pool in dhcpconf.pools %} | ||
range {{ pool|ipaddr('1')|ipaddr('address') }} {{ pool|ipaddr('-2')|ipaddr('address') }}; | ||
{% endfor %} | ||
{% endif %} | ||
default-lease-time {{ dhcpconf.default_lease_time|default(3600) }}; | ||
max-lease-time {{ dhcpconf.max_lease_time|default(7200) }}; | ||
option routers {{ dhcpconf.routers }}; | ||
{% if 'dns' in network.services %} | ||
option domain-name "{{ network.domain|default("example.com") }}"; | ||
option domain-name-servers {{ dhcpconf.dns }}; | ||
{% endif %} | ||
{% if 'ntp' in network.services %} | ||
option ntp-servers {{ dhcpconf.ntp }}; | ||
{% endif %} | ||
{% if dhcpconf.pxeboot_fname is defined %} | ||
filename "{{ dhcpconf.pxeboot_fname }}"; | ||
next-server {{ dhcpconf.pxeboot_next }}; | ||
{% endif %} | ||
{% if dhcpconf.allow_unknown is defined %} | ||
{% if dhcpconf.allow_unknown %} | ||
allow unknown-clients; | ||
{% else %} | ||
deny unknown-clients; | ||
{% endif %} | ||
{% endif %} | ||
} | ||
{% endfor %} | ||
{% if dhcp_networks|length >1 %} | ||
} | ||
|
||
{% if interface.hosts is defined %} | ||
{% endif %} | ||
{% endif %} | ||
{% endfor %} | ||
{% for network in sg_networks %} | ||
{% if network.hosts is defined %} | ||
group { | ||
{% for host in interface.hosts %} | ||
{% for host in network.hosts %} | ||
host {{ host.name }} { | ||
hardware ethernet {{ host.mac }}; | ||
fixed-address {{ host.addr }}; | ||
} | ||
{% endfor %} | ||
} | ||
{% endfor %} | ||
} | ||
{% endif %} | ||
{% endif %} | ||
{% endfor %} |