Is there any way to have an environment variable created by a task where that environment variable can be consumed by a lookup or filter?
I have read The environment: keyword does not affect Ansible itself, Ansible configuration settings, the environment for other users, or the execution of other plugins like lookups and filtershere.
long answer:
An action plugin could inject values into the Ansible environment, but since this is done in a subprocess, it won’t affect the main process or other forks. Most templating happens before the action plugin is called, but you could try to access the raw template instead of the resulting value (unsupported internal API, so might break at any point), to force rerunning of those templates so the filters/lookups/tests get the new environment variable.