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 the possibility to assign a default value to env lookup #34189

Closed
wants to merge 2 commits into from
Closed

Add the possibility to assign a default value to env lookup #34189

wants to merge 2 commits into from

Conversation

davidblaisonneau-orange
SUMMARY

By default lookup('env', ) returns an empty string if the variable does not
exists, and force the user to add boolean=True to the default() jinja filter
(see #15575)

This is a proposition to assign a default value to a environment
variable, directly in the lookup plugin, in the same way of os.getenv()
python function.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

plugins/lookup/env

ANSIBLE VERSION

ansible 2.4.2.0

ADDITIONAL INFORMATION
{{ lookup('env', 'OTHER_HOME')|default('playbook_dir/../other', true) }}

Can now also be written:

{{ lookup('env', 'OTHER_HOME, playbook_dir/../other') }}

By default lookup('env', ) returns an empty string if the variable does not
exists, and force the user to add boolean=True to the default() jinja filter
(see #15575)

This is a proposition to assign a default value to a environment
variable, directly in the lookup plugin, in the same way of os.getenv()
python function.

So:
{{ lookup('env', 'OTHER_HOME')|default('playbook_dir/../other', true) }}

Can be replaced by:
{{ lookup('env', 'OTHER_HOME, playbook_dir/../other') }}

Signed-off-by: Blaisonneau David <david.blaisonneau@orange.com>
@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 feature_pull_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 Dec 22, 2017
@ansibot
Copy link
Contributor

ansibot commented Dec 22, 2017

The test ansible-test sanity --test pylint [?] failed with the following error:

lib/ansible/plugins/lookup/env.py:8:0: misplaced-future __future__ import is not the first non docstring statement

click here for bot help

@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Dec 22, 2017
@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Dec 22, 2017
Signed-off-by: Blaisonneau David <david.blaisonneau@orange.com>
@ansibot ansibot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Dec 22, 2017
@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. 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 Dec 30, 2017
@sivel
Copy link
Member

sivel commented Jan 2, 2018

We have previously decided to not accept this specific change. Using the |default filter is our recommendation.

If you have further questions please stop by IRC or the mailing list:

@sivel sivel closed this Jan 2, 2018
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 5, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 feature This issue/PR relates to a feature request. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. 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.

None yet

4 participants