From 90228f880669e8186a8a09ce9d29427995a54b1a Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 4 Oct 2024 13:42:36 +0200 Subject: [PATCH] [roles/server/dhcpd] install dhcpd --- roles/server/dhcpd/defaults/main.yml | 10 +++++ roles/server/dhcpd/files/default/dhcpd.conf | 22 +++++++++++ roles/server/dhcpd/handlers/main.yml | 13 +++++++ roles/server/dhcpd/tasks/main.yml | 43 +++++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 roles/server/dhcpd/defaults/main.yml create mode 100644 roles/server/dhcpd/files/default/dhcpd.conf create mode 100644 roles/server/dhcpd/handlers/main.yml create mode 100644 roles/server/dhcpd/tasks/main.yml diff --git a/roles/server/dhcpd/defaults/main.yml b/roles/server/dhcpd/defaults/main.yml new file mode 100644 index 0000000..7eb5a14 --- /dev/null +++ b/roles/server/dhcpd/defaults/main.yml @@ -0,0 +1,10 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +# If not overridden in inventory or as a parameter, this is the value that will be used +# +--- +dhcpd_interfaces: "eth0" diff --git a/roles/server/dhcpd/files/default/dhcpd.conf b/roles/server/dhcpd/files/default/dhcpd.conf new file mode 100644 index 0000000..a564455 --- /dev/null +++ b/roles/server/dhcpd/files/default/dhcpd.conf @@ -0,0 +1,22 @@ +# +################################################ +### Managed by someone's ansible provisioner ### +################################################ +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +# dhcpd minimalistic config. Assuming Server's IPv4: 172.20.0.254 +# + +authoritative; +log-facility local7; +default-lease-time 18000; +max-lease-time 21600; +ddns-update-style none; + +subnet 172.20.0.0 netmask 255.255.0.0 { + range 172.20.1.1 172.20.1.254; + option routers 172.20.0.254; + option domain-name-servers 172.20.0.22; + option ntp-servers 172.20.0.254; +} diff --git a/roles/server/dhcpd/handlers/main.yml b/roles/server/dhcpd/handlers/main.yml new file mode 100644 index 0000000..0f3b2c9 --- /dev/null +++ b/roles/server/dhcpd/handlers/main.yml @@ -0,0 +1,13 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +--- +- name: restart isc-dhcp-server.service + systemd: + name: isc-dhcp-server.service + daemon_reload: yes + state: restarted + ignore_errors: yes diff --git a/roles/server/dhcpd/tasks/main.yml b/roles/server/dhcpd/tasks/main.yml new file mode 100644 index 0000000..fbd197b --- /dev/null +++ b/roles/server/dhcpd/tasks/main.yml @@ -0,0 +1,43 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +--- +- name: install dhcp-server + apt: + pkg: + - isc-dhcp-server + state: present + policy_rc_d: 101 + tags: "online" + ignore_errors: "{{ignore_online_errors | bool}}" + + +- name: set interfaces to serve + lineinfile: + name: /etc/default/isc-dhcp-server + regexp: '^INTERFACESv4=' + line: 'INTERFACESv4="{{dhcpd_interfaces}}"' + + +- name: copy dhcpd.conf + copy: + src: "{{item}}" + dest: "/etc/dhcp/dhcpd.conf" + mode: 0640 + owner: "root" + group: "root" + with_first_found: + - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/dhcpd.conf" + - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/dhcpd.conf" + - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/dhcpd.conf" + - "default/dhcpd.conf" + notify: restart isc-dhcp-server.service + + +- name: enable and start isc-dhcp-server.service + include_role: name="base/systemd/enable-and-start" + vars: + service_name: isc-dhcp-server.service -- 2.43.0