This guide provides a full Ansible playbook to install NSD with distro-aware package handling and service management for Debian 10+, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install NSD
hosts: nsd
become: true
vars:
dns_config_dir: /etc/nsd
tasks:
- name: Install package on Debian/Ubuntu
apt:
name:
- nsd
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install package on RHEL family
dnf:
name:
- nsd
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: nsd
state: started
enabled: true
- name: Verify binary is available
command: "nsd -V"
register: dns_version
changed_when: false
failed_when: false
- name: Show detected version output
debug:
var: dns_version.stdout
We develop tailored automation solutions for:
Let’s discuss your requirements: office@linux-server-admin.com | Contact