only fetch specific zone form api

main
Sebastian Gumprich 1 year ago
parent 8221c8009b
commit 11f6a9b7ec
  1. 2
      Makefile
  2. 5
      plugins/module_utils/helper.py
  3. 10
      plugins/modules/record.py
  4. 12
      plugins/modules/record_info.py
  5. 8
      plugins/modules/zone_info.py

@ -24,4 +24,4 @@ round: ## remove, build install
$(MAKE) syntax
$(MAKE) remove
$(MAKE) build
$(MAKE) install
$(MAKE) install

@ -37,13 +37,16 @@ class HetznerAPIHandler:
if self.TOKEN is None:
self.fail_json(msg='Unable to continue. No Hetzner DNS API Token is given.')
def get_zone_info(self):
def get_zone_info(self, zone_name):
try:
r = requests.get(
url="https://dns.hetzner.com/api/v1/zones",
headers={
"Auth-API-Token": self.TOKEN,
},
params={
"name": zone_name,
},
)
if r.status_code == 200:

@ -63,7 +63,7 @@ def main():
state = dict(type='str', default='present', choices=['present', 'absent']),
purge = dict(required=False, type='bool', default=True, aliases=['replace', 'overwrite', 'solo'])
)
module = AnsibleModule(
argument_spec=argument_spec,
required_if=[['state', 'present', ['value']]],
@ -81,7 +81,7 @@ def main():
purge = module.params.get("purge")
if zone_id is None:
zones = dns.get_zone_info()
zones = dns.get_zone_info(zone_name)
zone_id, zone_info = ZoneInfo(zones, zone_name)
if zone_id is None:
module.fail_json(msg='zone or zone_id: {msg}'.format(msg=error_codes.get(404, UE)))
@ -129,7 +129,7 @@ def main():
if record_changed and not purge:
record_exists = False
record_changed = False
if state == 'present':
if purge and len(record_ids) > 1:
for id in record_ids:
@ -179,7 +179,7 @@ def main():
)
module.exit_json(changed = change, record_id=record_id, record_info=this_record, past_record=past_record, diff=diff)
if __name__ == '__main__':
main()
main()

@ -18,7 +18,7 @@ EXAMPLES = '''
- name: fritzbox
type: AAAA
zone_name: osuv.de
'''
from ansible.module_utils.basic import *
@ -33,7 +33,7 @@ def main():
zone_name = dict(required=False, type='str'),
api_token = dict(required=False, type='str', no_log=True, aliases=['access_token'])
)
module = AnsibleModule(
argument_spec=argument_spec,
mutually_exclusive=[['zone_id', 'zone_name']],
@ -48,7 +48,7 @@ def main():
zone_name = module.params.get("zone_name")
if zone_id is None:
zones = dns.get_zone_info()
zones = dns.get_zone_info(zone_name)
zone_id = ZoneInfo(zones, zone_name)
records = dns.get_record_info(zone_id)
@ -62,10 +62,10 @@ def main():
if all(item in record.items() for item in filter.items()):
retval.append(record)
module.exit_json(changed = False, record_info=retval)
if __name__ == '__main__':
main()
main()

@ -34,11 +34,11 @@ def main():
name = module.params.get("name")
zones = dns.get_zone_info()
zones = dns.get_zone_info(name)
zone_id, zone_info = ZoneInfo(zones, name)
module.exit_json(changed = False, zone_id=zone_id, zone_info=zone_info)
if __name__ == '__main__':
main()
main()

Loading…
Cancel
Save