Re: [ansible-project] DNS Update (AD)

51 views
Skip to first unread message
Message has been deleted

Dick Visser

unread,
Apr 20, 2020, 10:52:25 AM4/20/20
to ansible...@googlegroups.com
Doesn't the win_dns_record module just do everything already?

Just one task and be done with it?




On Mon, 20 Apr 2020 at 15:26, Renato Marcandier <renato.m...@gmail.com> wrote:

Hello guys,


I am trying to run a playbook that does the following situation:


I want to update a current A record with a new IP address; if it doesn't exist, it will create a new A record.


My current playbook does the following tasks:


Check if the A record inside our DNS Manager exists.

  • If it doesn't, my playbook will create a new A record.
  • If it does, it will delete the current A record and recreate with a new IP address.


Just want to check if there is a better way to achieve it without delete and recreate the A record, I couldn't figure out a way to only update the current A record using "Set-DnsServerResourceRecord".


---


- hosts: all

  gather_facts: true

  vars: 

    dns_name: "test_01"

    ip: "10.10.10.13"


  tasks:


  - name: "Check a DNS record"

    win_shell: |

      try {

      (Get-DnsServerResourceRecord `

        -ZoneName "{{ dns_domain }}" `

        -name "{{ dns_name }}" `

        -RRType 'A' `

        -ErrorAction stop `

        -ComputerName "{{ dns_server }}").RecordData.IPv4Address.IPAddressToString

      } catch {

        write-host "failed"

      }

    delegate_to: "{{ mgmt_server }}"

    changed_when: false

    register: check_out


  - name: DNS output

    debug:

      var: check_out.stdout_lines[0]


   - name: Remove static record

     win_dns_record:

       name: "{{ dns_name }}"

       type: "A"

       state: absent

       zone: "{{ dns_domain }}"


   - name: Register

     win_shell: |

       Add-DnsServerResourceRecordA `

       -ZoneName "{{ dns_domain }}" `

       -name "{{ dns_name }}" `

       -AllowUpdateAny `

       -IPv4Address "{{ ip }}" `

       -ComputerName "{{ dns_server }}"

     delegate_to: "{{ mgmt_server }}"

     register: change_out

     throttle: 1


  - name: Change output

    debug:

      var: change_out

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/83b926d6-ecef-427d-8744-3483379410a0%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.
Reply all
Reply to author
Forward
0 new messages