# Task/playbook overwriting of vars

**URL:** <https://forum.ansible.com/t/task-playbook-overwriting-of-vars/44454>\
**Category:** Get Help\
**Created:** [September 10, 2025, 8:10am UTC](https://forum.ansible.com/t/task-playbook-overwriting-of-vars/44454 "2025-09-10T08:10:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adriansev](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/adriansev/32/4866_2.png) [@adriansev](https://forum.ansible.com/u/adriansev)\
**Post date:** [September 10, 2025, 8:10am UTC](https://forum.ansible.com/t/task-playbook-overwriting-of-vars/44454/1 "2025-09-10T08:10:30Z")

</div>

Hi! I have a situation that requires to have some default vars defined in the actual task definition.  
Can i count of these to be overwritten if in the playbook (that includes the said task) i define some other values for those variables?  
Thank you!

---

<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:** [September 10, 2025, 9:22am UTC](https://forum.ansible.com/t/task-playbook-overwriting-of-vars/44454/2 "2025-09-10T09:22:24Z")

</div>

No. It’s not possible. See [Understanding variable precedence](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#understanding-variable-precedence). Playbook vars (precedence 12-14) do not override the `task vars` (precedence 17).

```yaml
- debug:
    var: x
  vars:
    x: foo

```

Do not use `task vars` if you want to override them at the play level. Instead, use the [default](https://jinja.palletsprojects.com/en/latest/templates/#jinja-filters.default) filter. For example,

```yaml
- debug:
    var: x | d('foo')

```

* * *

As a sidenote: There are two more important use cases:

- Use the filter _default_ to override a module option’s defaults. For example,

```yaml
- lineinfile:
    create: "{{ create | d(true) }}"
    ...

```

- Use the special variable [omit](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_filters.html#making-variables-optional) to ‘enable’ the option (and keep the module option’s defaults).

```yaml
- lineinfile:
    create: "{{ create | d(omit) }}"
    ...

```

---

<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:** [October 18, 2025, 7:15am UTC](https://forum.ansible.com/t/task-playbook-overwriting-of-vars/44454/3 "2025-10-18T07:15:20Z")

</div>

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