ipa_dnsrecord: Allow for PTR Records (supporting reverse DNS) (#26709)

This commit is contained in:
Fran Fitzpatrick 2017-08-15 04:25:28 -05:00 committed by René Moser
parent 8ed7417ff9
commit 5fec649052

View file

@ -33,13 +33,15 @@ options:
record_type:
description:
- The type of DNS record name
- Currently, 'A', 'AAAA' is supported
- Currently, 'A', 'AAAA', and 'PTR' are supported
required: false
default: 'A'
choices: ['A', 'AAAA']
record_ip:
choices: ['A', 'AAAA', 'PTR']
record_value:
description:
- Manage DNS record name with this IP address.
- Manage DNS record name with this value.
- In the case of 'A' or 'AAAA' record types, this will be the IP address.
- In the case of 'PTR' record type, this will be the hostname.
required: true
state:
description: State to ensure
@ -85,14 +87,24 @@ EXAMPLES = '''
zone_name: example.com
record_name: vm-001
record_type: 'AAAA'
record_ip: '::1'
record_value: '::1'
# Ensure a PTR record is present
- ipa_dnsrecord:
ipa_host: spider.example.com
ipa_pass: Passw0rd!
state: present
zone_name: 2.168.192.in-addr.arpa
record_name: 5
record_type: 'PTR'
record_value: 'internal.ipa.example.com'
# Ensure that dns record is removed
- ipa_dnsrecord:
name: host01
zone_name: example.com
record_type: 'AAAA'
record_ip: '::1'
record_value: '::1'
ipa_host: ipa.example.com
ipa_user: admin
ipa_pass: topsecret
@ -123,9 +135,11 @@ class DNSRecordIPAClient(IPAClient):
def dnsrecord_add(self, zone_name=None, record_name=None, details=None):
item = dict(idnsname=record_name)
if details['record_type'] == 'A':
item.update(a_part_ip_address=details['record_ip'])
item.update(a_part_ip_address=details['record_value'])
elif details['record_type'] == 'AAAA':
item.update(aaaa_part_ip_address=details['record_ip'])
item.update(aaaa_part_ip_address=details['record_value'])
elif details['record_type'] == 'PTR':
item.update(ptr_part_hostname=details['record_value'])
return self._post_json(method='dnsrecord_add', name=zone_name, item=item)
@ -142,10 +156,12 @@ class DNSRecordIPAClient(IPAClient):
def get_dnsrecord_dict(details=None):
module_dnsrecord = dict()
if details['record_type'] == 'A' and details['record_ip']:
module_dnsrecord.update(arecord=details['record_ip'])
elif details['record_type'] == 'AAAA' and details['record_ip']:
module_dnsrecord.update(aaaarecord=details['record_ip'])
if details['record_type'] == 'A' and details['record_value']:
module_dnsrecord.update(arecord=details['record_value'])
elif details['record_type'] == 'AAAA' and details['record_value']:
module_dnsrecord.update(aaaarecord=details['record_value'])
elif details['record_type'] == 'PTR' and details['record_value']:
module_dnsrecord.update(ptrrecord=details['record_value'])
return module_dnsrecord
@ -161,7 +177,7 @@ def ensure(module, client):
ipa_dnsrecord = client.dnsrecord_find(zone_name, record_name)
module_dnsrecord = dict(record_type=module.params['record_type'],
record_ip=module.params['record_ip'])
record_value=module.params['record_value'])
changed = False
if state == 'present':
@ -191,13 +207,13 @@ def ensure(module, client):
def main():
record_types = ['A', 'AAAA']
record_types = ['A', 'AAAA', 'PTR']
module = AnsibleModule(
argument_spec=dict(
zone_name=dict(type='str', required=True),
record_name=dict(type='str', required=True, aliases=['name']),
record_type=dict(type='str', required=False, default='A', choices=record_types),
record_ip=dict(type='str', required=True),
record_value=dict(type='str', required=True),
state=dict(type='str', required=False, default='present', choices=['present', 'absent']),
ipa_prot=dict(type='str', required=False, default='https', choices=['http', 'https']),
ipa_host=dict(type='str', required=False, default='ipa.example.com'),