This guide provides a full Ansible playbook to install Unbound with distro-aware package handling and service management for Debian 10+, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install Unbound
hosts: unbound
become: true
vars:
dns_config_dir: /etc/unbound
tasks:
- name: Update package cache (Debian/Ubuntu)
apt:
update_cache: true
cache_valid_time: 3600
when: ansible_os_family == "Debian"
- name: Install package on Debian/Ubuntu
apt:
name:
- unbound
state: present
when: ansible_os_family == "Debian"
- name: Install package on RHEL family
dnf:
name:
- unbound
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: unbound
state: started
enabled: true
- name: Verify binary is available
command: "unbound -V"
register: dns_version
changed_when: false
failed_when: false
- name: Show detected version output
debug:
var: dns_version.stdout
Beyond this playbook, we offer:
Contact our automation team: office@linux-server-admin.com