1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Sort out parameter requirements for cloudflare_dns (#31800)

This module is mostly written to make room for the option of not
setting the `value` parameter while `state=absent`. That choice being
a feature, since it allows both for the removal of individual records
as well as the removal of full record sets.

The opposite goes for the `record` parameter, which needs to be defined
at least by its default value for the module to be able to produce any
meaningful result. Hence making it explicit as part of required_if.

The MX record type is already plenty covered. In addition to the
priority parameter having a default value, the `ensure_dns_record`
method does its own parameter checking.

SRV records on the other hand do need additional parameter
checking. Primarily with the `delete_dns_records` method in mind.

Fixes #23957
This commit is contained in:
Andreas Olsson 2018-01-11 18:03:54 +01:00 committed by ansibot
parent 3f4dfb2574
commit 7ac061139b

View file

@ -473,7 +473,8 @@ class CloudflareAPI(object):
content = params['value']
search_record = params['record']
if params['type'] == 'SRV':
content = str(params['weight']) + '\t' + str(params['port']) + '\t' + params['value']
if not (params['value'] is None or params['value'] == ''):
content = str(params['weight']) + '\t' + str(params['port']) + '\t' + params['value']
search_record = params['service'] + '.' + params['proto'] + '.' + params['record']
if params['solo']:
search_value = None
@ -616,22 +617,20 @@ def main():
),
supports_check_mode=True,
required_if=([
('state', 'present', ['record', 'type']),
('type', 'MX', ['priority', 'value']),
('type', 'SRV', ['port', 'priority', 'proto', 'service', 'value', 'weight']),
('type', 'A', ['value']),
('type', 'AAAA', ['value']),
('type', 'CNAME', ['value']),
('type', 'TXT', ['value']),
('type', 'NS', ['value']),
('type', 'SPF', ['value'])
('state', 'present', ['record', 'type', 'value']),
('state', 'absent', ['record']),
('type', 'SRV', ['proto', 'service']),
]
),
required_one_of=(
[['record', 'value', 'type']]
)
)
if module.params['type'] == 'SRV':
if not ((module.params['weight'] is not None and module.params['port'] is not None
and not (module.params['value'] is None or module.params['value'] == ''))
or (module.params['weight'] is None and module.params['port'] is None
and (module.params['value'] is None or module.params['value'] == ''))):
module.fail_json(msg="For SRV records the params weight, port and value all need to be defined, or not at all.")
changed = False
cf_api = CloudflareAPI(module)