Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom globals to the environment, and not per template #69278

Merged
merged 2 commits into from
Jun 8, 2020

Conversation

sivel
Copy link
Member

@sivel sivel commented May 1, 2020

SUMMARY

Add custom globals to the environment, and not per template

This produces an environment, that is more similar to what is used when calling templar.template. lookups are disable on the template if necessary.

This makes an environmentfilter filter more powerful, as it now has access to our custom globals.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME
lib/ansible/template/__init__.py
ADDITIONAL INFORMATION

@ansibot ansibot added affects_2.10 This issue/PR affects Ansible v2.10 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels May 1, 2020
@sivel
Copy link
Member Author

sivel commented May 1, 2020

An example of a filter plugin that could make filters for each lookup:

from jinja2.filters import environmentfilter

from ansible.plugins.loader import lookup_loader


def lookup_wrapper(lookup):
    @environmentfilter
    def inner(environment, *args, **kwargs):
        return environment.globals['q'](lookup, *args, **kwargs)
    return inner


class FilterModule(object):
    def filters(self):
        return {k._load_name: lookup_wrapper(k._load_name) for k in lookup_loader.all()}

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels May 1, 2020
@jimi-c jimi-c removed the needs_triage Needs a first human triage before being processed. label May 5, 2020
@ansibot ansibot added stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. core_review In order to be merged, this PR must follow the core review workflow. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels May 13, 2020
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 22, 2020
@sivel sivel marked this pull request as ready for review June 8, 2020 17:09
@ansibot ansibot added support:community This issue/PR relates to code supported by the Ansible community. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jun 8, 2020
@sivel sivel merged commit bfff953 into ansible:devel Jun 8, 2020
@ansible ansible locked and limited conversation to collaborators Jul 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.10 This issue/PR affects Ansible v2.10 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants