From 57e1063fc7ff6cf5453065d56ac7686f9fe4bf2b Mon Sep 17 00:00:00 2001 From: Kevin Breit Date: Wed, 29 May 2019 08:57:38 -0500 Subject: [PATCH] meraki_config_template - Remove mandatory network lookup (#56525) * Module only makes network lookups when needed instead of every execution * Formatting fixes --- .../56024-meraki_config_template-request-fix.yml | 2 ++ .../network/meraki/meraki_config_template.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/56024-meraki_config_template-request-fix.yml diff --git a/changelogs/fragments/56024-meraki_config_template-request-fix.yml b/changelogs/fragments/56024-meraki_config_template-request-fix.yml new file mode 100644 index 00000000000..dcf55e894c4 --- /dev/null +++ b/changelogs/fragments/56024-meraki_config_template-request-fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - meraki_config_template - Don't query all networks unless needed. diff --git a/lib/ansible/modules/network/meraki/meraki_config_template.py b/lib/ansible/modules/network/meraki/meraki_config_template.py index a11ef44a872..88956cb108d 100644 --- a/lib/ansible/modules/network/meraki/meraki_config_template.py +++ b/lib/ansible/modules/network/meraki/meraki_config_template.py @@ -229,9 +229,13 @@ def main(): if meraki.params['org_name']: org_id = meraki.get_org_id(meraki.params['org_name']) net_id = meraki.params['net_id'] - nets = meraki.get_nets(org_id=org_id) - if meraki.params['net_name']: - net_id = meraki.get_net_id(net_name=meraki.params['net_name'], data=nets) + nets = None + if net_id is None: + if meraki.params['net_name'] is not None: + nets = meraki.get_nets(org_id=org_id) + net_id = meraki.get_net_id(net_name=meraki.params['net_name'], data=nets) + else: + nets = meraki.get_nets(org_id=org_id) if meraki.params['state'] == 'query': meraki.result['data'] = get_config_templates(meraki, org_id) @@ -239,6 +243,8 @@ def main(): template_id = get_template_id(meraki, meraki.params['config_template'], get_config_templates(meraki, org_id)) + if nets is None: + nets = meraki.get_nets(org_id=org_id) if is_network_bound(meraki, nets, net_id, template_id) is False: template_bind = bind(meraki, net_id, @@ -261,6 +267,8 @@ def main(): template_id = get_template_id(meraki, meraki.params['config_template'], get_config_templates(meraki, org_id)) + if nets is None: + nets = meraki.get_nets(org_id=org_id) if is_network_bound(meraki, nets, net_id, template_id) is True: config_unbind = unbind(meraki, net_id)