1#!/usr/local/bin/python3.8 2# -*- coding: utf-8 -*- 3 4# Copyright: (c) 2020 VMware, Inc. All Rights Reserved. 5# SPDX-License-Identifier: GPL-3.0-only 6# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 7 8DOCUMENTATION = r''' 9--- 10module: win_dns_zone 11short_description: Manage Windows Server DNS Zones 12author: Joe Zollo (@joezollo) 13requirements: 14 - This module requires Windows Server 2012R2 or Newer 15description: 16 - Manage Windows Server DNS Zones 17 - Adds, Removes and Modifies DNS Zones - Primary, Secondary, Forwarder & Stub 18 - Task should be delegated to a Windows DNS Server 19options: 20 name: 21 description: 22 - Fully qualified name of the DNS zone. 23 type: str 24 required: true 25 type: 26 description: 27 - Specifies the type of DNS zone. 28 - When l(type=secondary), the DNS server will immediately attempt to 29 perform a zone transfer from the servers in this list. If this initial 30 transfer fails, then the zone will be left in an unworkable state. 31 This module does not verify the initial transfer. 32 type: str 33 choices: [ primary, secondary, stub, forwarder ] 34 dynamic_update: 35 description: 36 - Specifies how a zone handles dynamic updates. 37 - Secure DNS updates are available only for Active Directory-integrated 38 zones. 39 - When not specified during new zone creation, Windows will default this 40 to l(none). 41 type: str 42 choices: [ secure, none, nonsecureandsecure ] 43 state: 44 description: 45 - Specifies the desired state of the DNS zone. 46 - When l(state=present) the module will attempt to create the specified 47 DNS zone if it does not already exist. 48 - When l(state=absent), the module will remove the specified DNS 49 zone and all subsequent DNS records. 50 type: str 51 default: present 52 choices: [ present, absent ] 53 forwarder_timeout: 54 description: 55 - Specifies a length of time, in seconds, that a DNS server waits for a 56 remote DNS server to resolve a query. 57 - Accepts integer values between 0 and 15. 58 - If the provided value is not valid, it will be omitted and a warning 59 will be issued. 60 type: int 61 replication: 62 description: 63 - Specifies the replication scope for the DNS zone. 64 - l(replication=forest) will replicate the DNS zone to all domain 65 controllers in the Active Directory forest. 66 - l(replication=domain) will replicate the DNS zone to all domain 67 controllers in the Active Directory domain. 68 - l(replication=none) disables Active Directory integration and 69 creates a local file with the name of the zone. 70 - This is the equivalent of selecting l(store the zone in Active 71 Directory) in the GUI. 72 type: str 73 choices: [ forest, domain, legacy, none ] 74 dns_servers: 75 description: 76 - Specifies an list of IP addresses of the primary servers of the zone. 77 - DNS queries for a forwarded zone are sent to primary servers. 78 - Required if l(type=secondary), l(type=forwarder) or l(type=stub), 79 otherwise ignored. 80 - At least one server is required. 81 elements: str 82 type: list 83''' 84 85EXAMPLES = r''' 86- name: Ensure primary zone is present 87 community.windows.win_dns_zone: 88 name: wpinner.euc.vmware.com 89 replication: domain 90 type: primary 91 state: present 92 93- name: Ensure DNS zone is absent 94 community.windows.win_dns_zone: 95 name: jamals.euc.vmware.com 96 state: absent 97 98- name: Ensure forwarder has specific DNS servers 99 community.windows.win_dns_zone: 100 name: jamals.euc.vmware.com 101 type: forwarder 102 dns_servers: 103 - 10.245.51.100 104 - 10.245.51.101 105 - 10.245.51.102 106 107- name: Ensure stub zone has specific DNS servers 108 community.windows.win_dns_zone: 109 name: virajp.euc.vmware.com 110 type: stub 111 dns_servers: 112 - 10.58.2.100 113 - 10.58.2.101 114 115- name: Ensure stub zone is converted to a secondary zone 116 community.windows.win_dns_zone: 117 name: virajp.euc.vmware.com 118 type: secondary 119 120- name: Ensure secondary zone is present with no replication 121 community.windows.win_dns_zone: 122 name: dgemzer.euc.vmware.com 123 type: secondary 124 replication: none 125 dns_servers: 126 - 10.19.20.1 127 128- name: Ensure secondary zone is converted to a primary zone 129 community.windows.win_dns_zone: 130 name: dgemzer.euc.vmware.com 131 type: primary 132 replication: none 133 dns_servers: 134 - 10.19.20.1 135 136- name: Ensure primary DNS zone is present without replication 137 community.windows.win_dns_zone: 138 name: basavaraju.euc.vmware.com 139 replication: none 140 type: primary 141 142- name: Ensure primary DNS zone has nonsecureandsecure dynamic updates enabled 143 community.windows.win_dns_zone: 144 name: basavaraju.euc.vmware.com 145 replication: none 146 dynamic_update: nonsecureandsecure 147 type: primary 148 149- name: Ensure DNS zone is absent 150 community.windows.win_dns_zone: 151 name: marshallb.euc.vmware.com 152 state: absent 153 154- name: Ensure DNS zones are absent 155 community.windows.win_dns_zone: 156 name: "{{ item }}" 157 state: absent 158 loop: 159 - jamals.euc.vmware.com 160 - dgemzer.euc.vmware.com 161 - wpinner.euc.vmware.com 162 - marshallb.euc.vmware.com 163 - basavaraju.euc.vmware.com 164''' 165 166RETURN = r''' 167zone: 168 description: New/Updated DNS zone parameters 169 returned: When l(state=present) 170 type: dict 171 sample: 172 name: 173 type: 174 dynamic_update: 175 reverse_lookup: 176 forwarder_timeout: 177 paused: 178 shutdown: 179 zone_file: 180 replication: 181 dns_servers: 182''' 183