keep past records

v2.0.0
Markus Bergholz 1 year ago
parent aa548b9e5e
commit 851d0c5cc0
No known key found for this signature in database
GPG Key ID: B45724801354B174
  1. 11
      plugins/modules/record.py
  2. 225
      tests/tests.yml

@ -1,6 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Part of ansible markuman.hetzner_dns collection
DOCUMENTATION = '''
module: markuman.hetzner_dns.zone_info
'''
@ -96,14 +99,16 @@ def main():
record_changed = False
record_exists = False
change = False
past_record = None
for record in records.json()['records']:
if all(item in record.items() for item in find_record.items()):
record_exists = True
record_id = record.get('id')
past_record = record
if not all(item in record.items() for item in future_record.items()):
record_changed = True
else:
this_record = record
this_record = { 'record': record }
break
if state == 'present':
@ -130,11 +135,11 @@ def main():
r = dns.delete_record(record_id)
else:
change = False
this_record = None
this_record = { 'record': None }
record_id = None
module.exit_json(changed = change, record_id=record_id, record_info=this_record)
module.exit_json(changed = change, record_id=record_id, record_info=this_record, past_record=past_record)
if __name__ == '__main__':

@ -7,101 +7,132 @@
TEST_ZONE: osuv.de
tasks:
- name: fetch zone info
markuman.hetzner_dns.zone_info:
name: "{{ TEST_ZONE }}"
register: ZONES
- name: add record
markuman.hetzner_dns.record:
zone_id: "{{ ZONES.zone_id }}"
name: hetzner_dns_ansible_collection
value: osuv.de.
type: CNAME
ttl: 300
register: RECORD
- name: add record
assert:
that:
- RECORD is changed
- RECORD.record_info.record.ttl == 300
- name: fetch record info
markuman.hetzner_dns.record_info:
filter:
- name: hetzner_dns_ansible_collection
- name: test create
block:
- 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: osuv.de.
type: CNAME
ttl: 300
register: RECORD
- name: add record
assert:
that:
- RECORD is changed
- RECORD.record_info.record.ttl == 300
- name: fetch record info
markuman.hetzner_dns.record_info:
filter:
- name: hetzner_dns_ansible_collection
type: CNAME
zone_name: "{{ TEST_ZONE }}"
- 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: osuv.de.
type: CNAME
ttl: 300
register: RECORD
- name: add record no change
assert:
that:
- RECORD is not changed
- RECORD.past_record.ttl == 300
- RECORD.record_info.record.ttl == 300
- name: modify record change in check_mode
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
value: osuv.de.
type: CNAME
ttl: 60
check_mode: yes
register: RECORD
- name: change record check_mode
assert:
that:
- RECORD is changed
- RECORD.record_info.record.ttl == 60
- RECORD.past_record.ttl == 300
- name: modify record change
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
value: osuv.de.
type: CNAME
ttl: 60
register: RECORD
- name: change record
assert:
that:
- RECORD is changed
- RECORD.record_info.record.ttl == 60
- RECORD.past_record.ttl == 300
- name: del record
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
type: CNAME
state: absent
register: RECORD
- name: 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: del record
assert:
that:
- RECORD is not changed
always:
- name: always del record
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
type: CNAME
zone_name: "{{ TEST_ZONE }}"
- name: add record no change
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
value: osuv.de.
type: CNAME
ttl: 300
register: RECORD
- name: add record no change
assert:
that:
- RECORD is not changed
- name: modify record change in check_mode
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
value: osuv.de.
type: CNAME
ttl: 60
check_mode: yes
register: RECORD
- name: change record check_mode
assert:
that:
- RECORD is changed
- RECORD.record_info.record.ttl == 60
- name: modify record change
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
value: osuv.de.
type: CNAME
ttl: 60
register: RECORD
- name: change record
assert:
that:
- RECORD is changed
- RECORD.record_info.record.ttl == 60
- name: del record
markuman.hetzner_dns.record:
zone_name: "{{ TEST_ZONE }}"
name: hetzner_dns_ansible_collection
type: CNAME
state: absent
register: RECORD
- name: 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: del record
assert:
that:
- RECORD is not changed
state: absent

Loading…
Cancel
Save