- name: 'TYPE=A - creation (check mode)'
  win_dns_record: {zone: '{{ win_dns_record_zone }}', name: test1, value: 1.2.3.4, type: A}
  register: cmd_result
  check_mode: yes

- name: 'TYPE=A - creation get results (check mode)'
  win_command: powershell.exe "If (Get-DnsServerResourceRecord -ZoneName '{{ win_dns_record_zone }}' -Name 'test1' -RRType A -Node -ErrorAction:Ignore) { 'exists' } else { 'absent' }"
  register: cmd_result_actual
  changed_when: false

- name: 'TYPE=A - creation check results (check mode)'
  assert:
    that:
      - cmd_result is changed
      - cmd_result_actual.stdout == 'absent\r\n'

- name: 'TYPE=A - creation'
  win_dns_record: {zone: '{{ win_dns_record_zone }}', name: test1, value: 1.2.3.4, type: A}
  register: cmd_result

- name: 'TYPE=A - creation get results'
  win_command: powershell.exe "Get-DnsServerResourceRecord -ZoneName '{{ win_dns_record_zone }}' -Name 'test1' -RRType A -Node -ErrorAction:Ignore | Select -ExpandProperty RecordData | Select -ExpandProperty IPv4Address | Select -ExpandProperty IPAddressToString"
  register: cmd_result_actual
  changed_when: false

- name: 'TYPE=A - creation check results'
  assert:
    that:
      - cmd_result is changed
      - cmd_result_actual.stdout == '1.2.3.4\r\n'

- name: 'TYPE=A - creation (idempotent)'
  win_dns_record: {zone: '{{ win_dns_record_zone }}', name: test1, value: 1.2.3.4, type: A}
  register: cmd_result

- name: 'TYPE=A - creation get results (idempotent)'
  win_command: powershell.exe "Get-DnsServerResourceRecord -ZoneName '{{ win_dns_record_zone }}' -Name 'test1' -RRType A -Node -ErrorAction:Ignore | Select -ExpandProperty RecordData | Select -ExpandProperty IPv4Address | Select -ExpandProperty IPAddressToString"
  register: cmd_result_actual
  changed_when: false

- name: 'TYPE=A - creation check results (idempotent)'
  assert:
    that:
      - cmd_result is not changed
      - cmd_result_actual.stdout == '1.2.3.4\r\n'


- name: 'TYPE=A - update address (check mode)'
  win_dns_record: {zone: '{{ win_dns_record_zone }}', name: test1, value: 5.6.7.8, type: A}
  register: cmd_result
  check_mode: yes

- name: 'TYPE=A - update address get results (check mode)'
  win_command: powershell.exe "Get-DnsServerResourceRecord -ZoneName '{{ win_dns_record_zone }}' -Name 'test1' -RRType A -Node -ErrorAction:Ignore | Select -ExpandProperty RecordData | Select -ExpandProperty IPv4Address | Select -ExpandProperty IPAddressToString"
  register: cmd_result_actual
  changed_when: false

- name: 'TYPE=A - update address check results (check mode)'
  assert:
    that:
      - cmd_result is changed
      - cmd_result_actual.stdout == '1.2.3.4\r\n'

- name: 'TYPE=A - update address'
  win_dns_record: {zone: '{{ win_dns_record_zone }}', name: test1, value: 5.6.7.8, type: A}
  register: cmd_result

- name: 'TYPE=A - update address get results'
  win_command: powershell.exe "Get-DnsServerResourceRecord -ZoneName '{{ win_dns_record_zone }}' -Name 'test1' -RRType A -Node -ErrorAction:Ignore | Select -ExpandProperty RecordData | Select -ExpandProperty IPv4Address | Select -ExpandProperty IPAddressToString"
  register: cmd_result_actual
  changed_when: false

- name: 'TYPE=A - update address check results'
  assert:
    that:
      - cmd_result is changed
      - cmd_result_actual.stdout == '5.6.7.8\r\n'

- name: 'TYPE=A - update address (idempotent)'
  win_dns_record: {zone: '{{ win_dns_record_zone }}', name: test1, value: 5.6.7.8, type: A}
  register: cmd_result

- name: 'TYPE=A - update address get results (idempotent)'
  win_command: powershell.exe "Get-DnsServerResourceRecord -ZoneName '{{ win_dns_record_zone }}' -Name 'test1' -RRType A -Node -ErrorAction:Ignore | Select -ExpandProperty RecordData | Select -ExpandProperty IPv4Address | Select -ExpandProperty IPAddressToString"
  register: cmd_result_actual
  changed_when: false

- name: 'TYPE=A - update address check results (idempotent)'
  assert:
    that:
      - cmd_result is not changed
      - cmd_result_actual.stdout == '5.6.7.8\r\n'


- name: 'TYPE=A - update TTL (check mode)'
  win_dns_record: {zone: '{{ win_dns_record_zone }}', name: test1, value: 5.6.7.8, ttl: 7200, type: A}
  register: cmd_result
  check_mode: yes

- name: 'TYPE=A - update TTL get results (check mode)'
  win_command: powershell.exe "Get-DnsServerResourceRecord -ZoneName '{{ win_dns_record_zone }}' -Name 'test1' -RRType A -Node -ErrorAction:Ignore | Select -ExpandProperty TimeToLive | Select -ExpandProperty TotalSeconds"
  register: cmd_result_actual
  changed_when: false

- name: 'TYPE=A - update TTL check results (check mode)'
  assert:
    that:
      - cmd_result is changed
      - cmd_result_actual.stdout == '3600\r\n'

- name: 'TYPE=A - update TTL'
  win_dns_record: {zone: '{{ win_dns_record_zone }}', name: test1, value: 5.6.7.8, ttl: 7200, type: A}
  register: cmd_result

- name: 'TYPE=A - update TTL get results'
  win_command: powershell.exe "Get-DnsServerResourceRecord -ZoneName '{{ win_dns_record_zone }}' -Name 'test1' -RRType A -Node -ErrorAction:Ignore | Select -ExpandProperty TimeToLive | Select -ExpandProperty TotalSeconds"
  register: cmd_result_actual
  changed_when: false

- name: 'TYPE=A - update TTL check results'
  assert:
    that:
      - cmd_result is changed
      - cmd_result_actual.stdout == '7200\r\n'

- name: 'TYPE=A - update TTL (idempotent)'
  win_dns_record: {zone: '{{ win_dns_record_zone }}', name: test1, value: 5.6.7.8, ttl: 7200, type: A}
  register: cmd_result

- name: 'TYPE=A - update TTL get results (idempotent)'
  win_command: powershell.exe "Get-DnsServerResourceRecord -ZoneName '{{ win_dns_record_zone }}' -Name 'test1' -RRType A -Node -ErrorAction:Ignore | Select -ExpandProperty TimeToLive | Select -ExpandProperty TotalSeconds"
  register: cmd_result_actual
  changed_when: false

- name: 'TYPE=A - update TTL check results (idempotent)'
  assert:
    that:
      - cmd_result is not changed
      - cmd_result_actual.stdout == '7200\r\n'


- name: 'TYPE=A - remove record (check mode)'
  win_dns_record: {zone: '{{ win_dns_record_zone }}', name: test1, type: A, state: absent}
  register: cmd_result
  check_mode: yes

- name: 'TYPE=A - remove record get results (check mode)'
  win_command: powershell.exe "If (Get-DnsServerResourceRecord -ZoneName '{{ win_dns_record_zone }}' -Name 'test1' -RRType A -Node -ErrorAction:Ignore) { 'exists' } else { 'absent' }"
  register: cmd_result_actual
  changed_when: false

- name: 'TYPE=A - remove record check results (check mode)'
  assert:
    that:
      - cmd_result is changed
      - cmd_result_actual.stdout == 'exists\r\n'

- name: 'TYPE=A - remove record'
  win_dns_record: {zone: '{{ win_dns_record_zone }}', name: test1, type: A, state: absent}
  register: cmd_result

- name: 'TYPE=A - remove record get results'
  win_command: powershell.exe "If (Get-DnsServerResourceRecord -ZoneName '{{ win_dns_record_zone }}' -Name 'test1' -RRType A -Node -ErrorAction:Ignore) { 'exists' } else { 'absent' }"
  register: cmd_result_actual
  changed_when: false

- name: 'TYPE=A - remove record check results'
  assert:
    that:
      - cmd_result is changed
      - cmd_result_actual.stdout == 'absent\r\n'

- name: 'TYPE=A - remove record (idempotent)'
  win_dns_record: {zone: '{{ win_dns_record_zone }}', name: test1, type: A, state: absent}
  register: cmd_result

- name: 'TYPE=A - remove record get results (idempotent)'
  win_command: powershell.exe "If (Get-DnsServerResourceRecord -ZoneName '{{ win_dns_record_zone }}' -Name 'test1' -RRType A -Node -ErrorAction:Ignore) { 'exists' } else { 'absent' }"
  register: cmd_result_actual
  changed_when: false

- name: 'TYPE=A - remove record check results (idempotent)'
  assert:
    that:
      - cmd_result is not changed
      - cmd_result_actual.stdout == 'absent\r\n'
