diff --git a/ansible.cfg b/ansible.cfg index 6476e6f..b04e116 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -3,6 +3,7 @@ ask_vault_pass = True roles_path = ./roles retry_files_enabled = False inventory = ./hosts +filter_plugins = ./filter_plugins ansible_managed = Ansible managed, modified on %Y-%m-%d %H:%M:%S nocows = 1 forks = 15 diff --git a/roles/dhcpd/defaults/main.yml b/roles/dhcpd/defaults/main.yml new file mode 100644 index 0000000..9f4ae6b --- /dev/null +++ b/roles/dhcpd/defaults/main.yml @@ -0,0 +1,8 @@ +--- +dhcpd_interfaces: [] +dhcpd__default_lease_time: 600 +dhcpd__max_lease_time: 7200 +dhcpd__dns_servers: [] +dhcpd__domain_search: [] +dhcpd__subnets: [] +... diff --git a/roles/dhcpd/handlers/main.yml b/roles/dhcpd/handlers/main.yml new file mode 100644 index 0000000..1fe5942 --- /dev/null +++ b/roles/dhcpd/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: Restart isc-dhcp-server + systemd: + name: isc-dhcp-server.service + state: restarted +... diff --git a/roles/dhcpd/tasks/main.yml b/roles/dhcpd/tasks/main.yml new file mode 100644 index 0000000..9e8f12f --- /dev/null +++ b/roles/dhcpd/tasks/main.yml @@ -0,0 +1,29 @@ +--- +- name: Install isc-dhcp-server + apt: + name: isc-dhcp-server + +- name: Configure isc-dhcp-server + template: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + mode: u=rw,g=r,o= + owner: root + group: root + loop: + - src: dhcpd.conf.j2 + dest: /etc/dhcp/dhcpd.conf + - src: default.j2 + dest: /etc/default/isc-dhcp-server + notify: + - Restart isc-dhcp-server + +#- src: dhcpd6.conf.j2 +# dest: /etc/dhcp/dhcpd6.conf + +- name: Enable and start isc-dhcp-server + systemd: + name: isc-dhcp-server.service + state: started + enabled: true +... diff --git a/roles/dhcpd/templates/default.j2 b/roles/dhcpd/templates/default.j2 new file mode 100644 index 0000000..755f610 --- /dev/null +++ b/roles/dhcpd/templates/default.j2 @@ -0,0 +1,4 @@ +{{ ansible_managed | comment }} + +INTERFACESv4="{{ dhcpd__interfaces | join(' ') }}" +INTERFACESv6="" diff --git a/roles/dhcpd/templates/dhcpd.conf.j2 b/roles/dhcpd/templates/dhcpd.conf.j2 new file mode 100644 index 0000000..cd0c13f --- /dev/null +++ b/roles/dhcpd/templates/dhcpd.conf.j2 @@ -0,0 +1,28 @@ +{{ ansible_managed | comment }} + +default-lease-time {{ dhcpd__default_lease_time }}; +max-lease-time {{ dhcpd__max_lease_time }}; + +ddns-update-style none; + +authoritative; + +{% if dhcpd__dns_servers | default([]) %} +option domain-name-servers {{ dhcpd__dns_servers | join(", ") }}; +{% endif %} + +{% if dhcpd__domain_search | default([]) %} +option domain-search {{ dhcpd__domain_search | map("enquote") | join(", ") }}; +{% endif %} + +{% for subnet in dhcpd__subnets %} +subnet {{ subnet.network + | ansible.utils.ipaddr("network") }} + netmask {{ subnet.network + | ansible.utils.ipaddr("netmask") }} { + range {{ subnet.start }} {{ subnet.end }}; +{% if subnet.routers | default([]) %} + option routers {{ subnet.routers | join(", ") }}; +{% endif %} +} +{% endfor %}