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

omit does not work in task environment #25678

Closed
pjnagel opened this issue Jun 14, 2017 · 6 comments
Closed

omit does not work in task environment #25678

pjnagel opened this issue Jun 14, 2017 · 6 comments
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. c:playbook/task feature This issue/PR relates to a feature request. notification Notification category support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@pjnagel
Copy link

pjnagel commented Jun 14, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

task environment argument (all modules, not specific to a any module)

ANSIBLE VERSION
ansible 2.3.1.0
  config file = /home/pieter.nagel/setup/lautus_ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609]
CONFIGURATION

Nothing relevant

OS / ENVIRONMENT

Ubuntu 16.04

SUMMARY

Using the 'some_var | default(omit)' construct in the context of environment values does not work as expected.

If this is not expected to work, the docs should be clearer on this topic, and this bug report should be considered a wishlist item that this construct should be made to work.

STEPS TO REPRODUCE
- shell: 'printenv | grep XYZZY'
  environment:
    XYZZY: '{{ undefined_variable | default(omit) }}'
  register: result

- debug: msg='{{ result.stdout }}'
EXPECTED RESULTS

I expected result.stdout to be entirely empty.

ACTUAL RESULTS

The environment variable was set:

TASK [tau_devel : debug] **********************************************************************************************************************************************************************************************************************************************************
ok: [dev3.lautus.net] => {
    "msg": "XYZZY=__omit_place_holder__3a9b44ab3747672df782fe3743c15e71a5db5202\nSUDO_COMMAND=/bin/sh -c echo BECOME-SUCCESS-rqhncxoovhhmrvncugmtexxjsqombzdm; XYZZY=__omit_place_holder__3a9b44ab3747672df782fe3743c15e71a5db5202 /usr/bin/python3.5"
}

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report c:playbook/task needs_triage Needs a first human triage before being processed. python3 labels Jun 14, 2017
@nitzmahone nitzmahone added docs_report and removed bug_report needs_triage Needs a first human triage before being processed. labels Jun 15, 2017
@nitzmahone
Copy link
Member

Yeah, omit is currently only implemented for module args ATM, but I could definitely see uses for it in other contexts as well...

@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@ansibot
Copy link
Contributor

ansibot commented Sep 1, 2017

@abadger abadger removed the python3 label Sep 9, 2017
@ansibot
Copy link
Contributor

ansibot commented Nov 21, 2017

@ansibot ansibot added module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Nov 21, 2017
@ansibot ansibot added docs This issue/PR relates to or includes documentation. bug This issue/PR relates to a bug. feature This issue/PR relates to a feature request. and removed docs_report labels Mar 1, 2018
@pilou-
Copy link
Contributor

pilou- commented Jun 5, 2018

Current documentation states: it is possible to use the default filter to omit module parameters using the special omit variable is that not clear enough ? if so, docs can be removed.

@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:community This issue/PR relates to code supported by the Ansible community. labels Sep 17, 2018
@ansibot ansibot added needs_maintainer Ansibot is unable to identify maintainers for this PR. (Check `author` in docs or BOTMETA.yml) support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 3, 2018
@ansibot ansibot removed the needs_maintainer Ansibot is unable to identify maintainers for this PR. (Check `author` in docs or BOTMETA.yml) label Nov 10, 2018
openstack-gerrit pushed a commit to openstack/openstack-ansible-galera_server that referenced this issue Dec 20, 2018
In Id9c4f11b3536e7f9d510f5ef8e6d82a82a96adac we implemented a
failed_when condition to ignore the state of the service stop task
when `galera_ignore_cluster_state=true` is passed through.

Unfortunately, the omit filter does not work in a task context [1],
resulting in the task always failing because the omit placeholder
string is evaluated as true. This makes the task always fail when
running an upgrade.

In this patch we change the task flow to evaluate whether a service
exists, and if it does then to stop it - otherwise skip that task.
This should cater for the rolling replacement use-case and will
work in every other situation too.

[1] ansible/ansible#25678

Change-Id: Ib26c807057b9114e02ad32c759a5028555788363
@ansibot ansibot added the notification Notification category label Feb 17, 2019
@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. labels Sep 17, 2019
@samccann samccann removed the docs This issue/PR relates to or includes documentation. label Sep 25, 2020
@s-hertel
Copy link
Contributor

s-hertel commented Sep 3, 2021

You can use something like

environment: '{{ env|default(omit, true) }}'
vars:
  maybe_env:
    FOO: "foo"
    BAR: '{{ some_variable | default(omit) }}'
  env: '{{ dict(maybe_env|dictsort|rejectattr("1", "eq", omit)) }}'

Or compressed:

environment: '{{ dict(env|dictsort|rejectattr("1", "eq", omit))|default(omit, true) }}'
vars:
  env:
    FOO: "foo"
    BAR: '{{ some_variable | default(omit) }}'

as a workaround

@s-hertel
Copy link
Contributor

s-hertel commented Sep 3, 2021

We discussed this in backlog today and don't plan on implementing the feature since there are workarounds. We may revisit in the future once data tagging is possible.

@s-hertel s-hertel closed this as completed Sep 3, 2021
@ansible ansible locked and limited conversation to collaborators Oct 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. c:playbook/task feature This issue/PR relates to a feature request. notification Notification category support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

7 participants