slight var loading optimization (#78835)

Avoid having to recalculate these values since they don't change from first access
pull/78910/head
Brian Coca 2 years ago committed by GitHub
parent 3515b3c5fc
commit 95236c5569
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- optimized var loading by caching results as there is no variance in input during run.

@ -181,6 +181,8 @@ def merge_hash(x, y, recursive=True, list_merge='replace'):
def load_extra_vars(loader):
if not getattr(load_extra_vars, 'extra_vars', None):
extra_vars = {}
for extra_vars_opt in context.CLIARGS.get('extra_vars', tuple()):
data = None
@ -205,11 +207,14 @@ def load_extra_vars(loader):
else:
raise AnsibleOptionsError("Invalid extra vars data supplied. '%s' could not be made into a dictionary" % extra_vars_opt)
return extra_vars
setattr(load_extra_vars, 'extra_vars', extra_vars)
return load_extra_vars.extra_vars
def load_options_vars(version):
if not getattr(load_options_vars, 'options_vars', None):
if version is None:
version = 'Unknown'
options_vars = {'ansible_version': version}
@ -227,7 +232,9 @@ def load_options_vars(version):
if opt is not None:
options_vars['ansible_%s' % alias] = opt
return options_vars
setattr(load_options_vars, 'options_vars', options_vars)
return load_options_vars.options_vars
def _isidentifier_PY3(ident):

Loading…
Cancel
Save