Initial commit
This commit is contained in:
45
roles/dhcp/tasks/dhcp.yml
Normal file
45
roles/dhcp/tasks/dhcp.yml
Normal file
@@ -0,0 +1,45 @@
|
||||
---
|
||||
# Set state status for dhcp pool
|
||||
- name: Set state status for dhcp pool {{ item.id | default(item.interface) }}
|
||||
ansible.builtin.set_fact:
|
||||
dhcp_state: "{{ item.state | default('present') }}"
|
||||
|
||||
# Delete dhcp pool for interface
|
||||
- name: Delete dhcp pool for interface {{ item.id | default(item.interface) }}
|
||||
when: "'absent' in dhcp_state"
|
||||
uci:
|
||||
command: "absent"
|
||||
config: "dhcp"
|
||||
section: "{{ item.id | default(item.interface) }}"
|
||||
type: "dhcp"
|
||||
|
||||
# Create and configure dhcp pool for interface
|
||||
- name: Create and configure dhcp pool for interface
|
||||
when: "'present' in dhcp_state"
|
||||
block:
|
||||
# Create dhcp pool for interface
|
||||
- name: Create dhcp pool for interface {{ item.id | default(item.interface) }}
|
||||
uci:
|
||||
command: "add"
|
||||
config: "dhcp"
|
||||
section: "{{ item.id | default(item.interface) }}"
|
||||
type: "dhcp"
|
||||
|
||||
# Configure dhcp pool
|
||||
- name: Configure dhcp pool for {{ item.id | default(item.interface) }}
|
||||
uci:
|
||||
command: "set"
|
||||
config: "dhcp"
|
||||
section: "{{ item.id | default(item.interface) }}"
|
||||
type: "dhcp"
|
||||
value:
|
||||
interface: "{{ item.interface | default(omit) }}"
|
||||
dhcp_option: "{{ item.dhcp_option | default([]) | join(' ') }}"
|
||||
force: "{{ item.force | default(omit) }}"
|
||||
dhcpv4: "{{ item.dhcpv4 | default(omit) }}"
|
||||
leasetime: "{{ item.leasetime | default(omit) }}"
|
||||
limit: "{{ item.limit | default(omit) }}"
|
||||
start: "{{ item.start | default(omit) }}"
|
||||
ra: "{{ item.ra | default(omit) }}"
|
||||
dhcpv6: "{{ item.dhcpv6 | default(omit) }}"
|
||||
dns_service: "{{ item.dns_service | default(omit) }}"
|
||||
34
roles/dhcp/tasks/dnsmasq.yml
Normal file
34
roles/dhcp/tasks/dnsmasq.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
# Configure common options
|
||||
- name: Configure common options
|
||||
uci:
|
||||
command: "set"
|
||||
config: "dhcp"
|
||||
section: "@dnsmasq[0]"
|
||||
type: "dnsmasq"
|
||||
value:
|
||||
authoritative: "{{ dhcp_common.authoritative | default(omit) }}"
|
||||
boguspriv: "{{ dhcp_common.boguspriv | default(omit) }}"
|
||||
cachesize: "{{ dhcp_common.cachesize | default(omit) }}"
|
||||
domain: "{{ dhcp_common.domain | default(omit) }}"
|
||||
domainneeded: "{{ dhcp_common.domainneeded | default(omit) }}"
|
||||
dnssec: "{{ dhcp_common.dnssec | default(omit) }}"
|
||||
dnsseccheckunsigned: "{{ dhcp_common.dnsseccheckunsigned | default(omit) }}"
|
||||
expandhosts: "{{ dhcp_common.expandhosts | default(omit) }}"
|
||||
filterwin2k: "{{ dhcp_common.filterwin2k | default(omit) }}"
|
||||
fqdn: "{{ dhcp_common.fqdn | default(omit) }}"
|
||||
leasefile: "{{ dhcp_common.leasefile | default(omit) }}"
|
||||
local: "{{ dhcp_common.local | default(omit) }}"
|
||||
localise_queries: "{{ dhcp_common.localise_queries | default(omit) }}"
|
||||
localservice: "{{ dhcp_common.localservice | default(omit) }}"
|
||||
nonegcache: "{{ dhcp_common.nonegcache | default(omit) }}"
|
||||
nonwildcard: "{{ dhcp_common.nonwildcard | default(omit) }}"
|
||||
readethers: "{{ dhcp_common.readethers | default(omit) }}"
|
||||
rebind_protection: "{{ dhcp_common.rebind_protection | default(omit) }}"
|
||||
rebind_localhost: "{{ dhcp_common.rebind_localhost | default(omit) }}"
|
||||
rebind_domain: "{{ dhcp_common.rebind_domain | default([]) | join(' ') }}"
|
||||
resolvfile: "{{ dhcp_common.resolvfile | default([]) | join(' ') }}"
|
||||
server: "{{ dhcp_common.server | default([]) | join(' ') }}"
|
||||
serverlist: "{{ dhcp_common.serverlist | default(omit) }}"
|
||||
address: "{{ dhcp_common.address | default([]) | join(' ') }}"
|
||||
allservers: "{{ dhcp_common.allservers | default(omit) }}"
|
||||
40
roles/dhcp/tasks/host.yml
Normal file
40
roles/dhcp/tasks/host.yml
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
# Set static lease state status for host
|
||||
- name: Set static lease state status for host {{ item.id }}
|
||||
ansible.builtin.set_fact:
|
||||
static_lease_state: "{{ item.state | default('present') }}"
|
||||
|
||||
# Delete static lease for host
|
||||
- name: Delete static lease for host {{ item.id }}
|
||||
when: "'absent' in static_lease_state"
|
||||
uci:
|
||||
command: "absent"
|
||||
config: "dhcp"
|
||||
section: "{{ item.id }}"
|
||||
type: "host"
|
||||
|
||||
# Create and configure static lease for host
|
||||
- name: Create and configure static lease for host
|
||||
when: "'present' in static_lease_state"
|
||||
block:
|
||||
# Create static lease for host
|
||||
- name: Create static lease for host {{ item.id }}
|
||||
uci:
|
||||
command: "add"
|
||||
config: "dhcp"
|
||||
section: "{{ item.id | default('@host[-1]') }}"
|
||||
type: "host"
|
||||
|
||||
# Configure static lease for host
|
||||
- name: Configure static lease for host {{ item.id }}
|
||||
uci:
|
||||
command: "set"
|
||||
config: "dhcp"
|
||||
section: "{{ item.id | default('@host[-1]') }}"
|
||||
type: "host"
|
||||
value:
|
||||
name: "{{ item.name | default(omit) }}"
|
||||
ip: "{{ item.ip | default(omit) }}"
|
||||
mac: "{{ item.mac | default(omit) }}"
|
||||
tag: "{{ item.tag | default(omit) }}"
|
||||
dns: "{{ item.dns | default(omit) }}"
|
||||
20
roles/dhcp/tasks/main.yml
Normal file
20
roles/dhcp/tasks/main.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
# Configure dnsmasq section
|
||||
- name: Configure dnsmasq section
|
||||
ansible.builtin.include_tasks: dnsmasq.yml
|
||||
|
||||
# Configure dhcp section
|
||||
- name: Configure dhcp section
|
||||
ansible.builtin.include_tasks: dhcp.yml
|
||||
loop: "{{ dhcp_pools | default([]) }}"
|
||||
|
||||
# Configure host section
|
||||
- name: Configure host section
|
||||
ansible.builtin.include_tasks: host.yml
|
||||
loop: "{{ dhcp_leases | default([]) }}"
|
||||
|
||||
# Apply changes and reload DHCP service
|
||||
- name: Apply changes and reload dhcp
|
||||
uci:
|
||||
command: commit
|
||||
notify: Reload dhcp
|
||||
Reference in New Issue
Block a user