clean_facts - use correct variable when evaluating the string (#64284)

A regexp object has no .startswith() method, which caused an unnecessary
try/except block to be added to handle this.
This commit is contained in:
Sam Doran 2019-11-04 09:44:10 -05:00 committed by GitHub
parent 816e194e37
commit c67c23234a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 9 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- clean_facts - use correct variable to avoid unnecessary handling of ``AttributeError``

View file

@ -133,15 +133,12 @@ def clean_facts(facts):
# next we remove any connection plugin specific vars
for conn_path in connection_loader.all(path_only=True):
try:
conn_name = os.path.splitext(os.path.basename(conn_path))[0]
re_key = re.compile('^ansible_%s_' % conn_name)
for fact_key in fact_keys:
# most lightweight VM or container tech creates devices with this pattern, this avoids filtering them out
if (re_key.match(fact_key) and not fact_key.endswith(('_bridge', '_gwbridge'))) or re_key.startswith('ansible_become_'):
remove_keys.add(fact_key)
except AttributeError:
pass
conn_name = os.path.splitext(os.path.basename(conn_path))[0]
re_key = re.compile('^ansible_%s_' % conn_name)
for fact_key in fact_keys:
# most lightweight VM or container tech creates devices with this pattern, this avoids filtering them out
if (re_key.match(fact_key) and not fact_key.endswith(('_bridge', '_gwbridge'))) or fact_key.startswith('ansible_become_'):
remove_keys.add(fact_key)
# remove some KNOWN keys
for hard in C.RESTRICTED_RESULT_KEYS + C.INTERNAL_RESULT_KEYS: