# Getting "mapping values are not allowed here" error in Ansible dictionary task

**URL:** <https://forum.ansible.com/t/getting-mapping-values-are-not-allowed-here-error-in-ansible-dictionary-task/41646>\
**Category:** Get Help\
**Created:** [April 10, 2025, 9:35am UTC](https://forum.ansible.com/t/getting-mapping-values-are-not-allowed-here-error-in-ansible-dictionary-task/41646 "2025-04-10T09:35:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZoeNelson](https://avatars.discourse-cdn.com/v4/letter/z/2acd7d/32.png) [@ZoeNelson](https://forum.ansible.com/u/ZoeNelson)\
**Post date:** [April 10, 2025, 9:35am UTC](https://forum.ansible.com/t/getting-mapping-values-are-not-allowed-here-error-in-ansible-dictionary-task/41646/1 "2025-04-10T09:35:58Z")

</div>

Hey everyone,

I’ve been going through the [docs](https://www.concretecontractorsannarbormichigan.com/)[.ansible.com/ansible/latest/reference\_appendices/YAMLSyntax.html](https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html) and hit a strange issue that I can’t seem to sort out.

I’m trying to pass a dictionary of config options inside a task, and I keep getting a `mapping values are not allowed here` error. Here’s a trimmed-down version of what I’m working with:

```auto
vars:
  config_data: "{{ lookup('file', 'settings.json') }}"

tasks:
  - name: Apply configuration
    ansible.builtin.template:
      src: config.j2
      dest: "/etc/myapp/config.yaml"
      variables:
        settings: {
          mode: "advanced",
          enabled: true,
          threshold: 2.0
        }

```

I’ve double-checked the syntax, tried reformatting the dictionary, and even tested it with a YAML linter — everything _seems_ fine. But Ansible still complains. I’m wondering if this could be a conflict between how Jinja expressions are evaluated inside YAML or something subtle I’m overlooking.

Has anyone else run into this? Any tips or direction would be appreciated!

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [April 10, 2025, 10:26am UTC](https://forum.ansible.com/t/getting-mapping-values-are-not-allowed-here-error-in-ansible-dictionary-task/41646/2 "2025-04-10T10:26:15Z")

</div>

Change `variables` to `vars`?

```yaml
  - name: Apply configuration
    ansible.builtin.template:
      src: config.j2
      dest: "/etc/myapp/config.yaml"
      vars:
        settings:
          mode: advanced
          enabled: true
          threshold: 2.0

```

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [April 10, 2025, 4:08pm UTC](https://forum.ansible.com/t/getting-mapping-values-are-not-allowed-here-error-in-ansible-dictionary-task/41646/3 "2025-04-10T16:08:34Z")

</div>

`variables` is not a valid `template` option, neither is `vars`, but you can add `vars` to the task level, just need tt outdent from @chris’ example

In any case you are getting a YAML error as you cannot mix ‘shorthand’ and go back to standard YAML:

valid:

```auto
variables: { mode: advance, enabled: true}

```

also valid:

```auto
variables:
    mode: advance
    enabled: true

```

invalid:

```auto
variables: {
  mode: advance,
  enabled: true,
}

```

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [April 10, 2025, 4:21pm UTC](https://forum.ansible.com/t/getting-mapping-values-are-not-allowed-here-error-in-ansible-dictionary-task/41646/4 "2025-04-10T16:21:33Z")

</div>

Thanks @bcoca I made a typo with the indention of `vars` 🙄 this is want I wanted to suggest:

```auto
  - name: Apply configuration
    ansible.builtin.template:
      src: config.j2
      dest: "/etc/myapp/config.yaml"
    vars:
      settings:
        mode: advanced
        enabled: true
        threshold: 2.0

```
