ansible/test/integration/targets/azure_rm_dnszone/tasks/main.yml
2018-09-07 14:49:38 +08:00

268 lines
6.3 KiB
YAML

- name: Create random domain name
set_fact:
domain_name: "{{ resource_group | hash('md5') | truncate(16, True, '') + (65535 | random | string) }}"
- name: Create a DNS zone
azure_rm_dnszone:
resource_group: "{{ resource_group }}"
name: "{{ domain_name }}.com"
state: present
register: results
- assert:
that: results.changed
- name: Update DNS zone with tags
azure_rm_dnszone:
resource_group: "{{ resource_group }}"
name: "{{ domain_name }}.com"
state: present
tags:
test: modified
register: results
- assert:
that:
- results.changed
- results.state.tags.test == 'modified'
- name: Test check_mode
azure_rm_dnszone:
resource_group: "{{ resource_group }}"
name: "{{ domain_name }}.com"
state: present
tags:
test: new_modified
check_mode: yes
register: results
- assert:
that:
- results.changed
- results.state.tags.test == 'new_modified'
- results.check_mode == true
- name: Retrieve DNS Zone Facts
azure_rm_dnszone_facts:
resource_group: "{{ resource_group }}"
name: "{{ domain_name }}.com"
register: results
- name: Assert that facts module returned result
assert:
that:
- not results.changed
- results.ansible_facts.azure_dnszones[0].tags.test == 'modified'
#
# azure_rm_dnsrecordset test
#
- name: create "A" record set with multiple records
azure_rm_dnsrecordset:
resource_group: "{{ resource_group }}"
relative_name: www
zone_name: "{{ domain_name }}.com"
record_type: A
records:
- entry: 192.168.100.101
- entry: 192.168.100.102
- entry: 192.168.100.103
register: results
- name: Assert that A record set was created
assert:
that: results.changed
- name: re-run "A" record with same values
azure_rm_dnsrecordset:
resource_group: "{{ resource_group }}"
relative_name: www
zone_name: "{{ domain_name }}.com"
record_type: A
records:
- entry: 192.168.100.101
- entry: 192.168.100.102
- entry: 192.168.100.103
register: results
- name: Assert that A record set was not changed
assert:
that: not results.changed
- name: Update "A" record set with additional record
azure_rm_dnsrecordset:
resource_group: "{{ resource_group }}"
relative_name: www
zone_name: "{{ domain_name }}.com"
record_type: A
record_mode: append
records:
- entry: 192.168.100.104
register: results
- name: Assert that new record was appended
assert:
that:
- results.changed
- name: re-update "A" record set with additional record
azure_rm_dnsrecordset:
resource_group: "{{ resource_group }}"
relative_name: www
zone_name: "{{ domain_name }}.com"
record_type: A
record_mode: append
records:
- entry: 192.168.100.104
register: results
- name: Assert that A record set was not changed
assert:
that:
- not results.changed
- name: Remove 1 record from record set
azure_rm_dnsrecordset:
resource_group: "{{ resource_group }}"
relative_name: www
zone_name: "{{ domain_name }}.com"
record_type: A
records:
- entry: 192.168.100.101
- entry: 192.168.100.102
- entry: 192.168.100.103
register: results
- name: Assert that record was deleted
assert:
that:
- results.changed
- name: Check_mode test
azure_rm_dnsrecordset:
resource_group: "{{ resource_group }}"
relative_name: www
zone_name: "{{ domain_name }}.com"
record_type: A
records:
- entry: 192.168.100.105
check_mode: yes
register: results
- name: Assert that check_mode returns new state
assert:
that:
- results.changed
# FUTURE: add facts module calls to ensure that we really didn't touch anything
- name: create SRV records in a new record set
azure_rm_dnsrecordset:
resource_group: "{{ resource_group }}"
relative_name: "_sip._tcp.{{ domain_name }}.com"
zone_name: "{{ domain_name }}.com"
time_to_live: 7200
record_type: SRV
state: present
records:
- entry: sip.{{ domain_name }}.com
priority: 20
weight: 10
port: 5060
register: results
- name: Assert that SRV record set was created
assert:
that:
- results.changed
- name: create TXT records in a new record set
azure_rm_dnsrecordset:
resource_group: "{{ resource_group }}"
relative_name: "_txt.{{ domain_name }}.com"
zone_name: "{{ domain_name }}.com"
record_type: TXT
state: present
records:
- entry: "v=spf1 a -all"
- entry: "foo"
- entry:
- "bar"
- "baz"
register: results
- name: Assert that TXT record set was created
assert:
that:
- results.changed
#
# azure_rm_dnsrecordset_facts
#
- name: Retrieve DNS Record Set Facts for single Record Set
azure_rm_dnsrecordset_facts:
resource_group: "{{ resource_group }}"
zone_name: "{{ domain_name }}.com"
relative_name: www
record_type: A
register: results
- name: Assert that facts module returned result for single Record Set
assert:
that:
- not results.changed
- results.ansible_facts.azure_dnsrecordset[0].name == 'www'
- name: Retrieve DNS Record Set Facts for all Record Sets
azure_rm_dnsrecordset_facts:
resource_group: "{{ resource_group }}"
zone_name: "{{ domain_name }}.com"
register: results
- name: Assert that facts module returned result for all Record Sets
assert:
that:
- not results.changed
- results.ansible_facts.azure_dnsrecordset[0].name == '@'
- results.ansible_facts.azure_dnsrecordset[1].name == '@'
- results.ansible_facts.azure_dnsrecordset[4].name == 'www'
#
# azure_rm_dnsrecordset cleanup
#
- name: delete a record set
azure_rm_dnsrecordset:
resource_group: "{{ resource_group }}"
relative_name: www
zone_name: "{{ domain_name }}.com"
record_type: A
state: absent
register: results
- name: Assert that record set deleted
assert:
that: results.changed
- name: (idempotence test) re-run record set absent
azure_rm_dnsrecordset:
resource_group: "{{ resource_group }}"
relative_name: www
zone_name: "{{ domain_name }}.com"
record_type: A
state: absent
register: results
- name:
assert:
that: not results.changed
#
# azure_rm_dnszone cleanup
#
- name: Delete DNS zone
azure_rm_dnszone:
resource_group: "{{ resource_group }}"
name: "{{ domain_name }}.com"
state: absent