Hetzner DNS Ansible Collection
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

378 lines
10 KiB

---
- hosts: localhost
connection: local
gather_facts: no
vars:
TEST_ZONE: ansible-training.de
tasks:
- name: test create
block:
- name: test gracefull error handling
markuman.hetzner_dns.record:
zone_name: none_existing
name: hetzner_dns_ansible_collection
value: "osuv.de."
type: CNAME
ttl: 300
register: RECORD
ignore_errors: yes
- name: verify graceful error handling
assert:
that:
- RECORD is not changed
- RECORD is failed
- 'RECORD.msg == "zone_info: Not found."'
- name: fetch zone info
markuman.hetzner_dns.zone_info:
name: "{{ TEST_ZONE }}"
register: ZONES
- name: >
fetch zone info must also work
in check_mode
markuman.hetzner_dns.zone_info:
name: "{{ TEST_ZONE }}"
check_mode: yes
register: ZONES
- name: add record
markuman.hetzner_dns.record:
zone_id: "{{ ZONES.zone_id }}"
name: hetzner_dns_ansible_collection
value: "{{ TEST_ZONE }}."
type: CNAME
ttl: 300
register: RECORD
- name: assert add record 1
assert:
that:
- RECORD is changed
- RECORD.record_info.record.ttl == 300
- RECORD.record_info | count == 1
- name: fetch record info
markuman.hetzner_dns.record_info:
filter:
- name: hetzner_dns_ansible_collection
type: CNAME
zone_name: "{{ TEST_ZONE }}"
register: RECORD
- debug:
msg: "{{ RECORD }}"
- name: assert add record 2
assert:
that:
- RECORD.record_info[0].ttl == 300
- RECORD.record_info[0].type == 'CNAME'
- RECORD.record_info[0].value == "{{ TEST_ZONE }}."
- RECORD.record_info | count == 1
- name: >
fetch record info must
also work in check_mode
markuman.hetzner_dns.record_info:
filter:
- name: hetzner_dns_ansible_collection
type: CNAME
zone_name: "{{ TEST_ZONE }}"
check_mode: yes
- name: add record no change
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
value: "{{ TEST_ZONE }}."
type: CNAME
ttl: 300
register: RECORD
- name: assert add record no change
assert:
that:
- RECORD is not changed
- RECORD.past_record[0].ttl == 300
- RECORD.record_info.record.ttl == 300
- RECORD.record_info | count == 1
- name: modify record change in check_mode
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
value: "{{ TEST_ZONE }}."
type: CNAME
ttl: 60
check_mode: yes
register: RECORD
- name: assert change record check_mode
assert:
that:
- RECORD is changed
- RECORD.record_info.record.ttl == 60
- RECORD.past_record[0].ttl == 300
- RECORD.record_info | count == 1
- name: modify record change
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
value: "{{ TEST_ZONE }}."
type: CNAME
ttl: 60
register: RECORD
- name: assert change record
assert:
that:
- RECORD is changed
- RECORD.record_info.record.ttl == 60
- RECORD.past_record[0].ttl == 300
- RECORD.record_info | count == 1
- name: del record
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
type: CNAME
state: absent
register: RECORD
- name: assert del record
assert:
that:
- RECORD is changed
- name: del record no change
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
type: CNAME
state: absent
register: RECORD
- name: assert del record
assert:
that:
- RECORD is not changed
- name: add single A record
markuman.hetzner_dns.record:
zone_id: "{{ ZONES.zone_id }}"
name: hetzner_dns_ansible_collection
value: 1.1.1.1
type: A
ttl: 60
register: RECORD
- name: append A record
markuman.hetzner_dns.record:
zone_id: "{{ ZONES.zone_id }}"
name: hetzner_dns_ansible_collection
value: 8.8.8.8
type: A
purge: no
ttl: 60
register: RECORD
- name: append A record
markuman.hetzner_dns.record:
zone_id: "{{ ZONES.zone_id }}"
name: hetzner_dns_ansible_collection
value: 8.8.4.4
type: A
purge: no
ttl: 60
register: RECORD
- name: fetch record info
markuman.hetzner_dns.record_info:
filter:
- name: hetzner_dns_ansible_collection
type: A
zone_name: "{{ TEST_ZONE }}"
register: RECORD
- name: assert 3 A records
assert:
that:
- RECORD.record_info | count == 3
- name: fetch one record
markuman.hetzner_dns.record_info:
filter:
- name: hetzner_dns_ansible_collection
type: A
value: 8.8.8.8
zone_name: "{{ TEST_ZONE }}"
register: RECORD
- name: assert 1 A record
assert:
that:
- RECORD.record_info | count == 1
- name: delete single A record
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
value: 8.8.8.8
type: A
state: absent
- name: fetch record info
markuman.hetzner_dns.record_info:
filter:
- name: hetzner_dns_ansible_collection
type: A
zone_name: "{{ TEST_ZONE }}"
register: RECORD
- name: assert 2 A records
assert:
that:
- RECORD.record_info | count == 2
- name: delete all A records
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
type: A
state: absent
- name: fetch record info
markuman.hetzner_dns.record_info:
filter:
- name: hetzner_dns_ansible_collection
type: A
zone_name: "{{ TEST_ZONE }}"
register: RECORD
- name: assert 0 A records
assert:
that:
- RECORD.record_info | count == 0
- name: add record
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: website1
type: A
value: 127.0.0.1
- name: replace record
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: website1
type: A
value: 127.0.0.2
- name: fetch record info
markuman.hetzner_dns.record_info:
filter:
- name: website1
type: A
zone_name: "{{ TEST_ZONE }}"
register: RECORD
- debug:
msg: "{{ RECORD }}"
- name: assert 1 A record
assert:
that:
- RECORD.record_info | count == 1
- RECORD.record_info[0].ttl == 300
- RECORD.record_info[0].type == 'A'
- RECORD.record_info[0].value == '127.0.0.2'
- name: append record website1
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: website1
type: A
purge: no
value: 127.0.0.1
- name: fetch record info
markuman.hetzner_dns.record_info:
filter:
- name: website1
type: A
zone_name: "{{ TEST_ZONE }}"
register: RECORD
- name: assert 2 A record
assert:
that:
- RECORD.record_info | count == 2
- name: replace all
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: website1
type: A
purge: yes
value: 8.8.8.8
- name: fetch record info
markuman.hetzner_dns.record_info:
filter:
- name: website1
type: A
zone_name: "{{ TEST_ZONE }}"
register: RECORD
- name: assert 1 A record
assert:
that:
- RECORD.record_info | count == 1
- name: remove all records website1
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: website1
type: A
purge: yes
state: absent
- name: fetch record info
markuman.hetzner_dns.record_info:
filter:
- name: website1
type: A
zone_name: "{{ TEST_ZONE }}"
register: RECORD
- name: assert 0 A records
assert:
that:
- RECORD.record_info | count == 0
always:
- name: always del CNAME record
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
type: CNAME
state: absent
- name: always del A record
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
type: A
state: absent
- name: always del A record
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: website1
type: A
state: absent