dhcp: update role to template subnet configuration correctly

This commit is contained in:
Johanna Dorothea Reichmann 2020-06-07 20:13:46 +02:00
parent ce9572631d
commit adf511a35f
Signed by: transcaffeine
GPG Key ID: 03624C433676E465
3 changed files with 23 additions and 12 deletions

8
dhcp_server.yml Normal file
View File

@ -0,0 +1,8 @@
---
- name: "Setup ISC-DHCP for the internal network"
hosts: dhcp_server
become: true
roles:
- dhcp

View File

@ -13,6 +13,7 @@
group: root
mode: 0644
setype: dhcp_etc_t
validate: dhcpd -t
- name: Restart & enable DHCP-server
systemd:

View File

@ -21,34 +21,36 @@ option domain-name-servers {{ dhcp_common_name_servers|join(', ') }};
log-facility local7;
# Subnet definitions
{% for subnet in dhcp_subnets %}
subnet {{ subnet.net }} netmask {{ subnet.netmask }} {
option routers {{ subnet.routers }};
option broadcast-address {{ subnet.broadcast }};
option domain-name "{{ subnet.domain_name }}";
option domain-name-servers {{ subnet.domain_name_servers|join(', ') }};
{% if subnet.domain_search is defined and subnet.domain_search|length > 0 %}
option domain-search {{ subnet.domain_search | map('regex_replace', '(.*)', '\"\\1\"') | join(', ') }};
{% endif %}
{% if subnet.domain_search is defined and subnet.domain_search|length > 0 %}
option domain-search {{ subnet.domain_search | map('regex_replace', '^(.*)$', '\"\\1\"') | join(', ') }};
{% endif %}
{% if subnet.range_start is defined and subnet.range_end is defined %}
{% if subnet.range_start is defined and subnet.range_end is defined %}
range {{ subnet.range_start }} {{ subnet.range_end }};
{% endif %}
{% endif %}
{% if subnet.allow_unknown is defined and subnet.allow_unknown is sameas false %}
{% if subnet.allow_unknown is defined and subnet.allow_unknown is sameas false %}
deny unknown-clients;
{% else %}
{% else %}
allow unknown-clients;
{% endif %}
{% endif %}
{% for host in subnet.hosts %}
{% for host in subnet.hosts %}
host {{ host.name }} {
hardware ethernet {{ host.mac }};
{% if host.ip is defined %}
{% if host.ip is defined %}
fixed-address {{ host.ip }};
{% endif %}
{% endif %}
}
{% endfor %}
{% endfor %}
}
{% endfor %}