From 676bec54847e9462bace82d8948a8935a4ba2291 Mon Sep 17 00:00:00 2001 From: CWollinger Date: Mon, 23 Mar 2020 14:41:49 +0000 Subject: [PATCH] use module required_if so if statements not needed (#28) Co-authored-by: cwollinger --- plugins/modules/net_tools/ipwcli_dns.py | 27 ++++++------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/plugins/modules/net_tools/ipwcli_dns.py b/plugins/modules/net_tools/ipwcli_dns.py index 626f8ea96f..f7980310f0 100644 --- a/plugins/modules/net_tools/ipwcli_dns.py +++ b/plugins/modules/net_tools/ipwcli_dns.py @@ -188,39 +188,18 @@ class ResourceRecord(object): def create_naptrrecord(self): # create NAPTR record with the given params - if not self.preference: - self.module.fail_json(msg='missing required arguments for NAPTR record: preference') - - if not self.order: - self.module.fail_json(msg='missing required arguments for NAPTR record: order') - - if not self.service: - self.module.fail_json(msg='missing required arguments for NAPTR record: service') - - if not self.replacement: - self.module.fail_json(msg='missing required arguments for NAPTR record: replacement') - record = ('naptrrecord %s -set ttl=%s;container=%s;order=%s;preference=%s;flags="%s";service="%s";replacement="%s"' % (self.dnsname, self.ttl, self.container, self.order, self.preference, self.flags, self.service, self.replacement)) return record def create_srvrecord(self): # create SRV record with the given params - if not self.port: - self.module.fail_json(msg='missing required arguments for SRV record: port') - - if not self.target: - self.module.fail_json(msg='missing required arguments for SRV record: target') - record = ('srvrecord %s -set ttl=%s;container=%s;priority=%s;weight=%s;port=%s;target=%s' % (self.dnsname, self.ttl, self.container, self.priority, self.weight, self.port, self.target)) return record def create_arecord(self): # create A record with the given params - if not self.address: - self.module.fail_json(msg='missing required arguments for A record: address') - if self.dnstype == 'AAAA': record = 'aaaarecord %s %s -set ttl=%s;container=%s' % (self.dnsname, self.address, self.ttl, self.container) else: @@ -312,6 +291,12 @@ def run_module(): # supports check mode module = AnsibleModule( argument_spec=module_args, + required_if=[ + ['type', 'A', ['address']], + ['type', 'AAAA', ['address']], + ['type', 'SRV', ['port', 'target']], + ['type', 'NAPTR', ['preference', 'order', 'service', 'replacement']], + ], supports_check_mode=True )