Introduction

The community.general.nsupdate module add, modify, and delete DNS records using dynamic DNS updates (RFC 2136). This guide covers installation, parameters, practical examples, and troubleshooting for production use.

Quick Reference

- name: Basic nsupdate usage
  community.general.nsupdate:
    state: present

Parameters

ParameterRequiredDefaultDescription
stateNopresentDesired state (present/absent)
nameYes—Target resource name

Installation

# Install the collection
ansible-galaxy collection install community.general

# Verify installation
ansible-doc community.general.nsupdate

Basic Example

---
- name: Manage DNS Records Dynamically
  hosts: all
  become: true
  tasks:
    - name: Ensure resource is configured
      community.general.nsupdate:
        name: example
        state: present

Advanced Examples

Idempotent Configuration

- name: Configure with all options
  community.general.nsupdate:
    name: production
    state: present
  register: result

- name: Show result
  ansible.builtin.debug:
    var: result

Conditional Execution

- name: Only on specific OS
  community.general.nsupdate:
    name: example
    state: present
  when: ansible_os_family == "Debian"

Loop Over Multiple Items

- name: Configure multiple resources
  community.general.nsupdate:
    name: "{{ item }}"
    state: present
  loop:
    - resource1
    - resource2
    - resource3

Error Handling

- name: Handle failures gracefully
  block:
    - name: Attempt configuration
      community.general.nsupdate:
        name: example
        state: present
  rescue:
    - name: Log failure
      ansible.builtin.debug:
        msg: "Failed to configure nsupdate: {{ ansible_failed_result.msg }}"

Troubleshooting

ErrorCauseFix
Module not foundCollection not installedansible-galaxy collection install community.general
Permission deniedInsufficient privilegesAdd become: true
TimeoutNetwork/resource unavailableIncrease timeout, check connectivity
Idempotency issueModule reports changed every runCheck parameter values match desired state

Best Practices

  1. Use FQCN — always use community.general.nsupdate instead of short name
  2. Register results — capture output for conditional logic
  3. Handle errors — use block/rescue for graceful failure handling
  4. Test in check mode — run with --check before applying
  5. Pin collection version — specify version in requirements.yml
  • ansible.builtin.debug — Display variable values
  • ansible.builtin.assert — Validate conditions
  • ansible.builtin.set_fact — Set variables from task results

Conclusion

The community.general.nsupdate module provides idempotent add, modify, and delete DNS records using dynamic DNS updates (RFC 2136) Always use the FQCN, handle errors with block/rescue, and test with --check mode before production deployment.