dhcpd: create role with support for DHCPv4 only
This commit is contained in:
parent
5c780ffa62
commit
6bb2bbb54f
6 changed files with 76 additions and 0 deletions
|
@ -3,6 +3,7 @@ ask_vault_pass = True
|
||||||
roles_path = ./roles
|
roles_path = ./roles
|
||||||
retry_files_enabled = False
|
retry_files_enabled = False
|
||||||
inventory = ./hosts
|
inventory = ./hosts
|
||||||
|
filter_plugins = ./filter_plugins
|
||||||
ansible_managed = Ansible managed, modified on %Y-%m-%d %H:%M:%S
|
ansible_managed = Ansible managed, modified on %Y-%m-%d %H:%M:%S
|
||||||
nocows = 1
|
nocows = 1
|
||||||
forks = 15
|
forks = 15
|
||||||
|
|
8
roles/dhcpd/defaults/main.yml
Normal file
8
roles/dhcpd/defaults/main.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
dhcpd_interfaces: []
|
||||||
|
dhcpd__default_lease_time: 600
|
||||||
|
dhcpd__max_lease_time: 7200
|
||||||
|
dhcpd__dns_servers: []
|
||||||
|
dhcpd__domain_search: []
|
||||||
|
dhcpd__subnets: []
|
||||||
|
...
|
6
roles/dhcpd/handlers/main.yml
Normal file
6
roles/dhcpd/handlers/main.yml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
- name: Restart isc-dhcp-server
|
||||||
|
systemd:
|
||||||
|
name: isc-dhcp-server.service
|
||||||
|
state: restarted
|
||||||
|
...
|
29
roles/dhcpd/tasks/main.yml
Normal file
29
roles/dhcpd/tasks/main.yml
Normal file
|
@ -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
|
||||||
|
...
|
4
roles/dhcpd/templates/default.j2
Normal file
4
roles/dhcpd/templates/default.j2
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{{ ansible_managed | comment }}
|
||||||
|
|
||||||
|
INTERFACESv4="{{ dhcpd__interfaces | join(' ') }}"
|
||||||
|
INTERFACESv6=""
|
28
roles/dhcpd/templates/dhcpd.conf.j2
Normal file
28
roles/dhcpd/templates/dhcpd.conf.j2
Normal file
|
@ -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 %}
|
Loading…
Reference in a new issue