diff --git a/changelogs/fragments/env_inject.yml b/changelogs/fragments/env_inject.yml new file mode 100644 index 0000000000..3c36bf2231 --- /dev/null +++ b/changelogs/fragments/env_inject.yml @@ -0,0 +1,2 @@ +bugfixes: + - allow gathering env exception to work even when injection is off diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index b58e7767bf..b8e02437b8 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -278,8 +278,9 @@ class Task(Base, Conditional, Taggable, Become): try: env[k] = templar.template(v, convert_bare=False) except AnsibleUndefinedVariable as e: - if self.action in ('setup', 'gather_facts') and 'ansible_env' in to_native(e): - # ignore as fact gathering sets ansible_env + error = to_native(e) + if self.action in ('setup', 'gather_facts') and 'ansible_facts.env' in error or 'ansible_env' in error: + # ignore as fact gathering is required for 'env' facts return raise