Create a DNS Record With Ansible for Windows

In this blog post I will show you how to create a DNS A record with Ansible on a Windows Server 2019 DNS Server.

This post follows the post I have shown you on how to create a DNS zone on a Windows Server DNS Server using Ansible.

Ansible 2.10

The playbook that you are about to see is using a new module for creating DNS records. This module is part of the Ansible 2.10 collections feature that uses Ansible-galaxy.

This module will work with Ansible 2.9 however you will need to run the following command first and install the collection that has the module.

ansible-galaxy collection install community.windows 

Playbook

The playbook below will create a DNS record on my Domain Controller host. The A record name is testserver with an IP address of 10.1.1.21 and the DNS zone name is svc.corporate.local

---
- name: "Create a DNS record"
  hosts: dc
  tasks:
    - name: "Crerate A record"
      community.windows.win_dns_record:
         name: "testserver"
         type: "A"
         value: "10.1.1.21"
         zone: "svc.corporate.local"

All you need to do next is run the playbook and you re done. for more Ansible for Windows article visit our Ansible page.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.