This guide provides a full Ansible playbook to install dnsmasq with distro-aware package handling and service management for Debian 10+, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install dnsmasq
hosts: dnsmasq
become: true
vars:
dns_config_dir: /etc/dnsmasq
tasks:
- name: Install package on Debian/Ubuntu
apt:
name:
- dnsmasq
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install package on RHEL family
dnf:
name:
- dnsmasq
state: present
when: ansible_os_family == "RedHat"
- name: Create configuration directory
file:
path: "{{ dns_config_dir }}"
state: directory
mode: "0755"
- name: Enable and start service
service:
name: dnsmasq
state: started
enabled: true
- name: Verify binary is available
command: "dnsmasq --version"
register: dns_version
changed_when: false
failed_when: false
- name: Show detected version output
debug:
var: dns_version.stdout
dnssec and dnssec-check-unsigned directives. Ensure trust-anchor is configured. Supported since v2.70 (2014), enhanced in v2.90+.enable-ra for IPv6 SLAAC support. Requires --enable-ra compile flag (default on most distros).dns-0x20 for cache-poisoning protection (v2.91+, default-off).We develop tailored automation solutions for:
Let’s discuss your requirements: office@linux-server-admin.com | Contact