--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.