Skip to content

Commit

Permalink
Configuration Refactor
Browse files Browse the repository at this point in the history
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
m-wynn committed Mar 23, 2017
1 parent 7676fc8 commit 21b5477
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 43 deletions.
15 changes: 0 additions & 15 deletions defaults/main.yml

This file was deleted.

3 changes: 3 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- { role: sg-base }
15 changes: 14 additions & 1 deletion templates/10-dhcp.j2
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 %}"
78 changes: 51 additions & 27 deletions templates/dhcpd.conf.j2
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 %}

0 comments on commit 21b5477

Please sign in to comment.