From e6104e2ca352f85fba93643c6a8770d0ac550f77 Mon Sep 17 00:00:00 2001 From: Ibrahim Mkusa Date: Sun, 6 Oct 2024 10:29:53 -0400 Subject: [PATCH] bring up a dhcp service on a vm running rhel. --- ansible.cfg | 2 +- inventory/inventory | 3 +++ playbooks/network_services/dhcp.yml | 41 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 playbooks/network_services/dhcp.yml diff --git a/ansible.cfg b/ansible.cfg index 5e7e922..8f32ea9 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,3 +1,3 @@ [defaults] inventory=./inventory -remote_user="pollen" +remote_user="ansible" diff --git a/inventory/inventory b/inventory/inventory index 27e2456..1060ee2 100644 --- a/inventory/inventory +++ b/inventory/inventory @@ -1,6 +1,9 @@ [aws] aws ansible_user=ubuntu +[dhcp] +192.168.2.191 + [doc] doc ansible_user=pollen diff --git a/playbooks/network_services/dhcp.yml b/playbooks/network_services/dhcp.yml new file mode 100644 index 0000000..9383ec6 --- /dev/null +++ b/playbooks/network_services/dhcp.yml @@ -0,0 +1,41 @@ +--- +- name: sets up dhcp for a local homelab network between 0-255 hosts + hosts: dhcp + become: true + vars: + device: ens18 + tasks: + - name: install dhcp software on redhat platform + ansible.builtin.dnf: + name: dhcp-server + state: present + + - name: allow dhcp service on redhat platform + ansible.posix.firewalld: + service: dhcp + permanent: true + state: enabled + immediate: true + + - name: set up dhcpd.conf + ansible.builtin.template: + src: /home/mango/projects/homelab/templates/dhcpd.conf.j2 + dest: /etc/dhcp/dhcpd.conf + mode: '0644' + + - name: set the listening device + ansible.builtin.lineinfile: + path: /usr/lib/systemd/system/dhcpd.service + regexp: '^ExecStart=' + line: "ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid {{device}}" + + - name: daemon reload to restart changes + ansible.builtin.systemd: + daemon_reload: true + + + - name: start the dhcp service + ansible.builtin.service: + name: dhcpd + state: started + enabled: true