windows2008 R2 above DNS servers with ansible bulk management

Source: Internet
Author: User
Tags vars

Prepare: Install the DNS server net3.5 PowerShell Dnsshell plug-in. Dnsshell plug-in accessories inside the Ansible support environment also to be installed

Ansible Directory Structure Description:

.├── dnsshell  #PowerShell  dns Support Module  cp to c :\windows\system32\windowspowershell\v1.0\modules  is in folder │   ├── dnsshell.dll│    ├── dnsshell.format.ps1xml│   ├── dnsshell.psd1│   └──  en-us│       └── dnsshell.dll-help.xml├── dns.yml #  ansible  Use scripts ├── hosts #  client IP to store files └── roles    └── dns         ├── files         │   └── dns.ps1 # powershell   Script          └── tasks            └──  main.yml # ansible  using the script 
dns.yml  description:- hosts: dns #  Execute client list   variable can be set   vars:  #默认参数     parameter: dnszone  #创建主域   (dnszone  Add primary domain  A  record   Create an existing domain a  record  CNAME  add a domain name cname  record  delete  delete a domain name record   update  Update domain  )     Domain: test.com # test.com     name: a # a Records     ipaddress: 192.168.1.1 #  Records ip     ipaddress2: 192.168.1.1  #  Modify the domain name before it takes effect   roles:      - dns # ansible  Perform task 
main.yml  description:- name: sc dns  script:  dns.ps1 {{parameter}} {{domain}} {{name}} {{ipaddress}} {{ipaddress2}}  # Parameter Description parameter  perform label judgment   For example: Add domain name, delete domain name, modify domain name   Domain  domain name   name  domain name record  a record  mx records   ipaddress a records ip cname  domain name   ipaddress2   Modify the domain name resolution using the 
dns.ps1  Description # ************************************************************ # *                                                              * # *                  powershell Deploying DNS Scripts                      * # *                                                              * # ***********************************   #set-executionpolicy remotesigned #  Modify the parameters used by DNS ################### ##############################################################################  #参数申明param ($a, $b, $c, $d, $e) $parameter = $a $domain= $b $name= $c $ipaddress= $d $ipaddress2= $e #################################################### ############################################ #import-module dnsshell #  Import dnsshell  Module # # Create primary domain if  ($parameter  -eq  "DnsZone")  {new-dnszone -zonename  $Domain  -zonetype  primary}##  Add A record elseif  ($parameter  -eq  "a") {new-dnsrecord -zonename $ domain -name  $name  -recordtype A -ipaddress  $ipaddress}# #添加CNAME记录elseif   ($ parameter -eq  "CNAME") {new-dnsrecord -zonename   $Domain  -name  $name  - recordtype cname -hostname  $ipaddress}##  Delete DNS records elseif  ($parameter  -eq  "Delete") {$ARecord  =  get-wmiobject -namespace root\microsoftdns -class microsoftdns_resourcerecord - filter  "Containername= ' $Domain '  and ownername= ' $name. $Domain '  and recorddata= ' $ IPAddress ' "$ARecord. Delete ()}##  update DNS record elseif  ($parameter  -eq " Update ") {$ARecord  =  get-wmiobject -namespace root\microsoftdns -class microsoftdns_resourcerecord - filter  "Containername= ' $Domain '  and ownername= ' $name. $Domain '  and recorddata= ' $ IPAddress ' "$ARecord. Modify ($ARecord. TTL," $ipaddress 2 ")}else{exit}

Additional instructions:

Add primary domain:ansible-playbook -i hosts dns.yml -verbose --extra-vars  "Parameter=dnszone  domain=test.com "Add  a record ansible-playbook -i hosts dns.yml -verbose -- extra-vars  "parameter=a domain=test.com name=www ipaddress=192.168.1.1" add   CNAME record ansible-playbook -i hosts dns.yml -verbose --extra-vars  "Parameter=cname  domain=test.com name=test ipaddress= deletion record: ansible-playbook -i hosts  dns.yml -verbose --extra-vars  "parameter=deletedomain=test.com name=www ipaddress= 192.168.1.1 "  ansible-playbook -i hosts dns.yml -verbose --extra-vars  "parameter=delete domain=test.com name=test ipaddress=www.test.com. #  Point cannot be canceled     Update Records  ansible-playbook -i hosts dns.yml -verbose --extra-vars  Parameter=update domain=test.com name=www ipaddress=192.168.1.1 ipaddress2=192.168.1.2 " ansible-playbook -i hosts  dns.yml -verbose --extra-vars  "parameter=update domain=test.com name=test  Ipaddress=www.test.com. ipaddress2=www.baidu.com. "      Full code Download attachment

This article is from the "Growth record" blog, so be sure to keep this source http://juestnow.blog.51cto.com/1515305/1876484

windows2008 R2 above DNS servers with ansible bulk management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.