• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

UnixArena

  • Home
  • kubernetes
  • DevOps
    • Terraform
    • Jenkins
    • Docker
    • Openshift
      • OKD
    • Ansible engine
    • Ansible Tower
      • AWX
    • Puppet
  • Cloud
    • Azure
    • AWS
    • Openstack
    • Docker
  • VMware
    • vCloud Director
    • VMware-Guests
    • Vcenter Appliance 5.5
    • vC OPS
    • VMware SDDC
    • VMware vSphere 5.x
      • vSphere Network
      • vSphere DS
      • vShield Suite
    • VMware vSphere 6.0
    • VSAN
    • VMware Free Tools
  • Backup
    • Vembu BDR
    • Veeam
    • Nakivo
    • Azure Backup
    • Altaro VMBackup
    • Spinbackup
  • Tutorials
    • Openstack Tutorial
    • Openstack Beginner’s Guide
    • VXVM-Training
    • ZFS-Tutorials
    • NetApp cDot
    • LVM
    • Cisco UCS
    • LDOM
    • Oracle VM for x86
  • Linux
    • How to Articles
    • Q&A
    • Networking
    • RHEL7
  • DevOps Instructor-led Training
  • Contact

Automation – Add DNS A Record using Ansible Playbook

March 23, 2020 By Cloud_Devops 1 Comment

DNS resource records added automatically when windows instances is registered on domain. For Linux instances, you have to add the records manually on DNS server. Let’s explorer that how to create A records in DNS using Ansible Playbook. This playbook can be integrated as part of server provisioning workflow to speed up the build process.

Ansible Version – ansible 2.7.8

Step by Step Procedure:

1. Login to Ansible server.

2. Create a ansible playbook to create DNS records. Depends on environment and security restrictions, you need to find an option that could work for you.

DNS Server : DNSServerzone1
Operating System: Windows 2016 / 2012

Playbook:

---
- hosts: DNSServerzone1
  gather_facts: no 
  tasks:  
   - name: Add A record for newly build server
     win_shell: "Add-DnsServerResourceRecordA -Name {{ServerName}} -ZoneName {{Domain}} -AllowUpdateAny -IPv4Address {{IPAddress}} -TimeToLive 01:00:00"
     when: DOMAIN == "{{Domain}}" 

Variables:

  • ServerName
  • Domain
  • IPAddress

3. Create windows DNS server inventory according to the server security settings. In my example, DNS servers are allowed to communicate using 5985 (http) port for winrm.

Example:

[wintelDNS]
DNSServerzone1.dc.net

[wintelDNS:vars]
 ansible_connection=winrm
 ansible_winrm_server_cert_validation=ignore
 ansible_winrm_transport=kerberos
 ansible_ssh_port=5985
 ansible_user=ADMIN@DC.NET
 ansible_password=ADMINPASS 

4. Execute the playbook against the DNS server inventory to create the required A record.

# ansible-playbook -i inventory playbook_name -e ServerName=SERVER_NAME -e Domain=DC.NET -e IPAddress=192.168.3.98

5. We have successfully added A Records in DNS server. Records will take few minutes to populate in other DNS servers.

Ansible too have pre-written module(win_dns_recordĀ ) to fulfill this requirement. Please checkout in Ansible documentation for more information.

Filed Under: Ansible engine, Ansible Tower, Configuration Management Tagged With: Ansible, DNS, Sample Playbooks

Reader Interactions

Comments

  1. matthew curry says

    June 2, 2020 at 1:18 am

    Thanks for the post, do you have an example of a dns creation? Removal is easy, or using the ones you mentioned? I like your approach though a bit better for my use case.

    Either way, thanks for the info!
    Matt Curry

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Follow UnixArena

  • Facebook
  • LinkedIn
  • Twitter

Copyright © 2025 · UnixArena ·

Go to mobile version