Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnsmasq - use dhcp-hostdir #1801

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion roles/dnsmasq/tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
become: true
ansible.builtin.file:
mode: "0755"
path: "{{ cifmw_dnsmasq_basedir }}"
path: "{{ cifmw_dnsmasq_basedir }}/dhcp-hosts.d"
state: "{{ (_act == 'cleanup') | ternary('absent', 'directory') }}"

- name: Manage systemd unit file
Expand Down
38 changes: 21 additions & 17 deletions roles/dnsmasq/tasks/manage_host.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,38 @@

- name: Compute entry
ansible.builtin.set_fact:
_host_entry: |
{% if cifmw_dnsmasq_host_ipv4 is defined and cifmw_dnsmasq_host_ipv4 | length > 0 -%}
_host_entry: >
{% set data = [cifmw_dnsmasq_host_mac] -%}
{% if cifmw_dnsmasq_host_ipv4 is defined and cifmw_dnsmasq_host_ipv4 | length > 0 -%}
{% set _ = data.append(cifmw_dnsmasq_host_ipv4) -%}
{% set _ = data.append(cifmw_dnsmasq_host_name) if
cifmw_dnsmasq_host_name is defined and cifmw_dnsmasq_host_name | length > 0 -%}
dhcp-host={{ data | join(',') }}
{% endif -%}
{% if cifmw_dnsmasq_host_ipv6 is defined and cifmw_dnsmasq_host_ipv6 | length > 0 -%}
{% set data = [cifmw_dnsmasq_host_mac] -%}
{% set _ = data.append('['~cifmw_dnsmasq_host_ipv6~']') -%}
{% endif -%}
{% set _ = data.append(cifmw_dnsmasq_host_name) if
cifmw_dnsmasq_host_name is defined and cifmw_dnsmasq_host_name | length > 0 -%}
dhcp-host={{ data | join(',') }}
{% endif -%}
{{ data | join(',') }}

- name: Debug _host_entry
ansible.builtin.debug:
var: _host_entry

- name: Manage host entry
- name: Manage host entry - add
become: true
when:
- cifmw_dnsmasq_host_state == 'present'
ansible.builtin.copy:
content: "{{ _host_entry }}"
dest: "{{ cifmw_dnsmasq_basedir }}/dhcp-hosts.d/{{ cifmw_dnsmasq_host_mac }}"
mode: '0644'
owner: root
group: root

- name: Manage host entry - remove
become: true
when:
- cifmw_dnsmasq_host_state == 'absent'
notify: Restart dnsmasq
ansible.builtin.blockinfile:
block: "{{ _host_entry }}"
dest: "{{ cifmw_dnsmasq_basedir }}/{{ cifmw_dnsmasq_host_network }}-hosts.conf"
create: true
mode: "0644"
state: "{{ cifmw_dnsmasq_host_state }}"
marker: "## {mark} {{ cifmw_dnsmasq_host_mac }}"
validate: "/usr/sbin/dnsmasq -C %s --test"
ansible.builtin.file:
state: absent
path: "{{ cifmw_dnsmasq_basedir }}/dhcp-hosts.d/{{ cifmw_dnsmasq_host_mac }}"
2 changes: 1 addition & 1 deletion roles/dnsmasq/templates/cifmw-dnsmasq.conf.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Managed by ci-framework/dnsmasq

user=dnsmasq
group=dnsmasq
pid-file=/var/run/cifmw-dnsmasq.pid
Expand All @@ -10,3 +9,4 @@ dhcp-leasefile=/var/lib/dnsmasq/cifmw-dnsmasq.leases
{% endif %}

conf-dir={{ cifmw_dnsmasq_basedir }},*.conf
dhcp-hostsdir="{{ cifmw_dnsmasq_basedir }}/dhcp-hosts.d"
cjeanner marked this conversation as resolved.
Show resolved Hide resolved