ansible/roles/dhcpd/templates/dhcpd.conf.j2

79 lines
2.7 KiB
Django/Jinja

authoritative;
ddns-update-style none;
# custom options
option arch code 93 = unsigned integer 16;
# logging
on commit {
log(info,
concat("Client ",
binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)),
" requests ",
binary-to-ascii(16, 8, ":", option dhcp-parameter-request-list),
" - ",
pick-first-value(option vendor-class-identifier, "no vendor-id"),
" - ",
pick-first-value(option user-class, "no user-class"))
);
}
# pxe clients
class "PXEClient" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
next-server 172.20.20.10;
if exists user-class and option user-class = "iPXE" {
filename "https://boot.foo.sh/boot.ipxe";
} else {
if option arch = 00:07 {
filename "ipxe.efi";
} else {
filename "undionly.kpxe";
}
}
}
subnet {{ intnet | ansible.utils.ipaddr('network') }} netmask {{ intnet | ansible.utils.ipaddr('netmask') }} {
default-lease-time 86400;
max-lease-time 604800;
option subnet-mask {{ intnet | ansible.utils.ipaddr('netmask') }};
option broadcast-address {{ intnet | ansible.utils.ipaddr('broadcast') }};
option routers {{ intnet | ansible.utils.ipaddr(1) | ansible.utils.ipaddr('address')}};
option domain-name "{{ intdomain }}";
option domain-name-servers {{ intnet | ansible.utils.ipaddr(10) | ansible.utils.ipaddr('address') }}, {{ intnet | ansible.utils.ipaddr(11) | ansible.utils.ipaddr('address') }}, {{ intnet | ansible.utils.ipaddr(12) | ansible.utils.ipaddr('address') }};
use-host-decl-names on;
{% if network_interfaces[0].vlan == 30 %}
range {{ intnet | ansible.utils.ipaddr(100) | ansible.utils.ipaddr('address') }} {{ intnet | ansible.utils.ipaddr(200) | ansible.utils.ipaddr('address') }};
{% endif %}
}
{% for hostname in hostvars %}
{% if hostvars[hostname]['network_interfaces'] is defined %}
{% for interface in hostvars[hostname]['network_interfaces'] %}
{% if interface['vlan'] == network_interfaces[0].vlan and interface['mac'] is defined %}
{% if interface['ipaddr'] is defined %}
{% set ipaddr = interface['ipaddr'] %}
{% else %}
{% set ipaddr = '172.20.21.' + interface['mac'].split(':')[5] | int(base=16) | string %}
{% endif %}
host {{ hostname }} {
option host-name "{{ hostname }}";
hardware ethernet {{ interface['mac'] }};
fixed-address {{ ipaddr }};
}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% for host in ldap_hosts.results %}
host {{ host['cn'] }} {
option host-name "{{ host['cn'] }}";
hardware ethernet {{ host['macAddress'] }};
fixed-address {{ host['ipHostNumber'] }};
}
{% endfor %}