Initial commit of dhcpd/tftpd role
Change-Id: Ia6526e593100c9bbe935347105c5b3932f5e2641
diff --git a/tasks/Debian.yml b/tasks/Debian.yml
new file mode 100644
index 0000000..99692cc
--- /dev/null
+++ b/tasks/Debian.yml
@@ -0,0 +1,22 @@
+---
+# dhcpd tasks/Debian.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+- name: Install dhcpd and tftp packages (Debian)
+ apt:
+ name:
+ - "isc-dhcp-server"
+ - "tftpd-hpa"
+ state: "present"
+ update_cache: true
+ cache_valid_time: 3600
+
+- name: Set dhcpd listening interfaces
+ lineinfile:
+ path: "/etc/default/isc-dhcp-server"
+ line: "INTERFACESv4=\"{{ dhcpd_interfaces | join(' ') }}\""
+ regex: "^INTERFACESv4=.*"
+ notify:
+ - "dhcpd-restart"
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644
index 0000000..a030609
--- /dev/null
+++ b/tasks/main.yml
@@ -0,0 +1,44 @@
+---
+# dhcpd tasks/main.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+- name: include OS-specific vars
+ include_vars: "{{ ansible_os_family }}.yml"
+
+- name: include OS-specific tasks
+ include_tasks: "{{ ansible_os_family }}.yml"
+
+- name: Create dhcpd.conf from template
+ template:
+ src: dhcpd.conf.j2
+ dest: "{{ dhcpd_config_dir }}/dhcpd.conf"
+ backup: true
+ mode: "0644"
+ owner: root
+ group: root
+ # validate: 'dhcpd -t -cf %s' # Does not work...
+ notify:
+ - dhcpd-restart
+
+- name: Copy tftpd served files
+ copy:
+ src: "{{ item }}"
+ dest: "{{ tftpd_boot_dir }}/{{ item }}"
+ owner: root
+ group: "{{ tftpd_groupname }}"
+ mode: "0644"
+ with_items: "{{ tftpd_files }}"
+
+- name: Enable and start dhcpd
+ service:
+ name: "{{ dhcpd_service }}"
+ enabled: true
+ state: started
+
+- name: Enable and start tftpd
+ service:
+ name: "{{ tftpd_service }}"
+ enabled: true
+ state: started