diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2018-07-12 16:12:42 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-12 16:12:42 -0400 |
commit | 006f08da99b89f018d8a34bee97fb6f511ec7039 (patch) | |
tree | 9281ed2141a1444b27917c83f55cd5f7dfd17e19 /lib/ansible/vars | |
parent | a4a37e8dfbadb8084f29e2ae201e5a8db864ecd9 (diff) | |
download | ansible-006f08da99b89f018d8a34bee97fb6f511ec7039.tar.gz |
Fix fact cleaning (#42595)
* fix fact cleanup
fixes #41684
Diffstat (limited to 'lib/ansible/vars')
-rw-r--r-- | lib/ansible/vars/clean.py | 7 | ||||
-rw-r--r-- | lib/ansible/vars/manager.py | 4 |
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/ansible/vars/clean.py b/lib/ansible/vars/clean.py index c83709df4d..64bb042054 100644 --- a/lib/ansible/vars/clean.py +++ b/lib/ansible/vars/clean.py @@ -63,8 +63,13 @@ def clean_facts(facts): fact_keys = set(data.keys()) # first we add all of our magic variable names to the set of # keys we want to remove from facts + # NOTE: these will eventually disappear in favor of others below for magic_var in C.MAGIC_VARIABLE_MAPPING: remove_keys.update(fact_keys.intersection(C.MAGIC_VARIABLE_MAPPING[magic_var])) + + # remove common connection vars + remove_keys.update(fact_keys.intersection(C.COMMON_CONNECTION_VARS)) + # next we remove any connection plugin specific vars for conn_path in connection_loader.all(path_only=True): try: @@ -72,7 +77,7 @@ def clean_facts(facts): 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')): + 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 diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py index 07669ec625..01525f08e5 100644 --- a/lib/ansible/vars/manager.py +++ b/lib/ansible/vars/manager.py @@ -43,7 +43,7 @@ from ansible.template import Templar from ansible.utils.listify import listify_lookup_plugin_terms from ansible.utils.vars import combine_vars from ansible.utils.unsafe_proxy import wrap_var -from ansible.vars.clean import namespace_facts +from ansible.vars.clean import namespace_facts, clean_facts try: from __main__ import display @@ -313,7 +313,7 @@ class VariableManager: # push facts to main namespace if C.INJECT_FACTS_AS_VARS: - all_vars = combine_vars(all_vars, wrap_var(facts)) + all_vars = combine_vars(all_vars, wrap_var(clean_facts(facts))) else: # always 'promote' ansible_local all_vars = combine_vars(all_vars, wrap_var({'ansible_local': facts.get('ansible_local', {})})) |