# Omit and the dict lookup

**URL:** <https://forum.ansible.com/t/omit-and-the-dict-lookup/45197>\
**Category:** Get Help\
**Tags:** jinja2\
**Created:** [January 26, 2026, 5:47pm UTC](https://forum.ansible.com/t/omit-and-the-dict-lookup/45197 "2026-01-26T17:47:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [January 26, 2026, 5:47pm UTC](https://forum.ansible.com/t/omit-and-the-dict-lookup/45197/1 "2026-01-26T17:47:12Z")

</div>

I’m seeing unexpected effects when using the `omit` value with the `ansible.builtin.dict` lookup. I think I understand _what_ it’s doing, but I’m coming up short in the _why_ department.

Here’s a sample playbook that demonstrates what happens when NOT using the `omit` magic value.

```yaml
---
- name: Ansible omit games
  hosts: localhost
  gather_facts: false
  vars:
    ords:
      ones: 11111
      twos: 22222
      threes: 33333
      fours: 44444
      fives: 55555
    evens:
      - twos
      - fours
  tasks:
    - name: Print data
      ansible.builtin.debug:
        msg:
          - ords: '{{ ords }}'
          - evens: '{{ evens }}'
          - evens_x_omit: '{{ evens | product(["omit"]) }}'
          - same_as_a_dict: '{{ dict(evens | product(["omit"])) }}'
          - ords_combined_with_that_dict:
             '{{ ords | combine(dict(evens | product(["omit"]))) }}'

```

Note in particular that `"omit"` above is just a 4-leter double-quoted string in every case, not the special `omit` value. The above produces these totally expected results:

```yaml
  msg:
  - ords:
      fives: 55555
      fours: 44444
      ones: 11111
      threes: 33333
      twos: 22222
  - evens:
    - twos
    - fours
  - evens_x_omit:
    - - twos
      - omit
    - - fours
      - omit
  - same_as_a_dict:
      fours: omit
      twos: omit
  - ords_combined_with_that_dict:
      fives: 55555
      fours: omit
      ones: 11111
      threes: 33333
      twos: omit

```

So far so good. Now remove the double-quotes from all the `"omit"`s in that last task so we get the special `omit` value instead. And remove uninteresting `ords` and `evens` to same space.

```yaml
    - name: Print data
      ansible.builtin.debug:
        msg:
          - evens_x_omit: '{{ evens | product([omit]) }}'
          - same_as_a_dict: '{{ dict(evens | product([omit])) }}'
          - ords_combined_with_that_dict:
             '{{ ords | combine(dict(evens | product([omit]))) }}'

```

and that produces this output:

```yaml
  msg:
  - evens_x_omit:
    - - twos
      - __omit_place_holder__ baa56393a508bede3535cf10e0a2430226693e95
    - - fours
      - __omit_place_holder__ baa56393a508bede3535cf10e0a2430226693e95
  - same_as_a_dict: {}
  - ords_combined_with_that_dict:
      fives: 55555
      ones: 11111
      threes: 33333

```

In this case, `evens_x_omit` contains exactly what one would expect: each value from `evens` paired with the special `omit` value.

However, feeding that to the `[ansible.builtin.]dict` lookup to produce `same_as_a_dict` has the surprising effect of omitting the key:values pairs where the value is the special `omit` value! I had thought that `omit` only had an effect when used in _module parameters_. But here we are with an apparently empty `dict`. I didn’t see that coming.

If that’s not surprising enough, if we use that “empty” `dict` in the `combine` filter, its emptiness somehow manifests in such a way to cause the combined dict’s `twos` and `fours` be omitted! It’s as if we’ve tricked the `combine` filter to have the effect that `ansible.utils.remove_keys` was designed for.

Maybe there’s something about `omit`ting key:value pairs from dictionaries that takes place when closing a “`{{}}`” context?  
Something that doesn’t apply to list values?  
Is this a recent thing, or has it been this way for a long time?  
Is this intentional? I don’t recall every seeing this behavior documented before.

Interested to know what’s really going on here. Thanks for watchin’.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 26, 2026, 7:13pm UTC](https://forum.ansible.com/t/omit-and-the-dict-lookup/45197/2 "2026-01-26T19:13:17Z")

</div>

Before 2.19, when `omit` is the value of a key, the key is removed. This only happens with dicts, no other data structures.

As of 2.19, `omit`, now not a special text placeholder, gets removed from all data structures, never showing up with the `__omit*` placeholder text.

As for:

> [@utoddl](#):
>
> I had thought that `omit` only had an effect when used in _module parameters_.

I mean yes, you are feeding that to `debug`, and the removal in pre 2.19 is recursive. `msg` is a “module” parameter, and thus, the recursive removal will nuke the keys associated with the `omit` values.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [January 26, 2026, 7:47pm UTC](https://forum.ansible.com/t/omit-and-the-dict-lookup/45197/3 "2026-01-26T19:47:22Z")

</div>

Oh! That’s a couple more things I hadn’t considered: recursion/data structure depth and Ansible version. I’ve come to ignore that for the entertainment value; it delivers!

Thanks for the heads-up.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [January 26, 2026, 7:55pm UTC](https://forum.ansible.com/t/omit-and-the-dict-lookup/45197/4 "2026-01-26T19:55:55Z")

</div>

I see different results in 2.20.1

```yaml
- debug:
    msg: "{{ evens | product([omit]) }}"
  vars:
    evens: [twos, fours]

```

```auto
ok: [localhost] =>
    msg:
    - - twos
    - - fours

```

```yaml
- debug:
    msg: "{{ d1 | combine(d2) }}"
  vars:
    d1: {x: foo, y: bar, z: baz}
    d2: {x: foo, y: omit}

```

```auto
ok: [localhost] =>
    msg:
        x: foo
        y: omit
        z: baz

```

[[source code](https://github.com/vbotka/ansible_qa/blob/master/tasks/forum-45197.yml)]

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 25, 2026, 7:56pm UTC](https://forum.ansible.com/t/omit-and-the-dict-lookup/45197/5 "2026-02-25T19:56:03Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
