79 lines
2.6 KiB
YAML
79 lines
2.6 KiB
YAML
---
|
|
- name: Set DHCP configuration variables
|
|
set_fact:
|
|
br_if: "br_{{ gateway_config.lab_name }}"
|
|
dhcp_tag: "{{ gateway_config.lab_name }}"
|
|
|
|
- name: Calculate DHCP range based on role
|
|
set_fact:
|
|
dhcp_start: "{{ gateway_config.subnet | ipaddr('10') | ipaddr('address') if gateway_config.dhcp_role == 'primary' else gateway_config.subnet | ipaddr('128') | ipaddr('address') }}"
|
|
dhcp_limit: "{{ 118 if gateway_config.dhcp_role == 'primary' else 118 }}"
|
|
when: gateway_config.dhcp_mode == "simple"
|
|
|
|
- name: Calculate DHCP range for failover simulation
|
|
set_fact:
|
|
dhcp_start: "{{ gateway_config.subnet | ipaddr('10') | ipaddr('address') }}"
|
|
dhcp_limit: 236
|
|
when: gateway_config.dhcp_mode == "failover"
|
|
|
|
- name: Remove existing DHCP configuration for this lab
|
|
shell: |
|
|
uci delete dhcp.{{ dhcp_tag }} 2>/dev/null || true
|
|
uci commit dhcp
|
|
changed_when: true
|
|
|
|
- name: Configure DHCP server
|
|
shell: |
|
|
uci set dhcp.{{ dhcp_tag }}='dhcp'
|
|
uci set dhcp.{{ dhcp_tag }}.interface='{{ br_if }}'
|
|
uci set dhcp.{{ dhcp_tag }}.start='{{ dhcp_start | ipaddr('host') }}'
|
|
uci set dhcp.{{ dhcp_tag }}.limit='{{ dhcp_limit }}'
|
|
uci set dhcp.{{ dhcp_tag }}.leasetime='12h'
|
|
uci add_list dhcp.{{ dhcp_tag }}.dhcp_option='3,{{ gateway_config.subnet | ipaddr("1") | ipaddr("address") }}'
|
|
uci add_list dhcp.{{ dhcp_tag }}.dhcp_option='6,{{ gateway_config.subnet | ipaddr("1") | ipaddr("address") }}'
|
|
uci commit dhcp
|
|
changed_when: true
|
|
|
|
- name: Configure DNS domain for lab network
|
|
shell: |
|
|
uci set dhcp.{{ dhcp_tag }}.domain='{{ gateway_config.lab_name }}.lab'
|
|
uci set dhcp.{{ dhcp_tag }}.local='/{{ gateway_config.lab_name }}.lab/'
|
|
uci commit dhcp
|
|
changed_when: true
|
|
|
|
- name: Set DHCP authoritative mode based on role
|
|
shell: |
|
|
uci set dhcp.{{ dhcp_tag }}.authoritative='{{ "1" if gateway_config.dhcp_role == "primary" else "0" }}'
|
|
uci commit dhcp
|
|
changed_when: true
|
|
when: gateway_config.dhcp_mode == "failover"
|
|
|
|
- name: Restart dnsmasq
|
|
shell: /etc/init.d/dnsmasq restart
|
|
changed_when: true
|
|
|
|
- name: Wait for dnsmasq to start
|
|
shell: pgrep dnsmasq
|
|
register: dnsmasq_check
|
|
retries: 5
|
|
delay: 2
|
|
until: dnsmasq_check.rc == 0
|
|
changed_when: false
|
|
|
|
- name: Verify DHCP configuration
|
|
shell: |
|
|
echo "=== DHCP Configuration ==="
|
|
uci show dhcp.{{ dhcp_tag }}
|
|
echo ""
|
|
echo "=== dnsmasq Process ==="
|
|
ps | grep dnsmasq | grep -v grep
|
|
echo ""
|
|
echo "=== DHCP Leases ==="
|
|
cat /tmp/dhcp.leases 2>/dev/null || echo "No leases yet"
|
|
register: dhcp_status
|
|
changed_when: false
|
|
|
|
- name: Display DHCP status
|
|
debug:
|
|
var: dhcp_status.stdout_lines
|