summaryrefslogtreecommitdiffstats
path: root/ansible/deployment_poc/tasks/configure_dhcp.yml
blob: 1be9fcd3d811cbda13f9eedc0cfed3e3fcf8cd1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
---
- name: Configure DHCP
  block:
  - name: Set DHCP host OS
    set_fact:
      dhcp_os: "{{ hostvars[dhcp_host]['platforms'][0] }}"
  
  - name: Insert DHCP host block
    ansible.builtin.blockinfile:
      #backup: yes 
      block: "{{ lookup('template', '../templates/dhcpd.conf.j2') }}"
      marker: "### {mark} Ansible managed block for {{ vm_name }} ###"
      path: "/etc/dhcpd.conf"
    #delegate_to: "{{ dhcp_host }}"
    become: yes
    become_method: doas
    when: dhcp_os == 'openbsd-x86_64'

  - name: Restart dhcpd
    ansible.builtin.command:
      argv:
      - /usr/bin/doas
      - rcctl
      - restart
      - dhcpd
    when: dhcp_os == 'openbsd-x86_64'
 
  - name: Insert DHCP static mapping
    vyos.vyos.vyos_config:
      backup: yes
      backup_options:
        dir_path: "/tmp/"
      comment: "Configured as part of {{ vm_name }} deployment"
      lines:
      - "set service dhcp-server shared-network-name LAN subnet {{ prefix_display }} static-mapping {{ vm_name }} mac-address {{ mac_address }}"
      - "set service dhcp-server shared-network-name LAN subnet {{ prefix_display }} static-mapping {{ vm_name }} ip-address {{ ip_address }}"
      save: no # CHANGE BEFORE ROLLOUT
    when: dhcp_os == 'vyos-x86_64'
  delegate_to: "{{ dhcp_host }}"