# Using jinja macros in tasks templates

**URL:** <https://forum.ansible.com/t/using-jinja-macros-in-tasks-templates/30272>\
**Category:** Ansible Developer\
**Created:** [May 6, 2019, 4:30pm UTC](https://forum.ansible.com/t/using-jinja-macros-in-tasks-templates/30272 "2019-05-06T16:30:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![user19](https://avatars.discourse-cdn.com/v4/letter/u/3be4f8/32.png) [@user19](https://forum.ansible.com/u/user19)\
**Post date:** [May 6, 2019, 4:30pm UTC](https://forum.ansible.com/t/using-jinja-macros-in-tasks-templates/30272/1 "2019-05-06T16:30:04Z")

</div>

Hi!

The case is, I want to define some simple jinja macros, to simplify some common filters / conditionals combinations without using python directly (my point is: supporting those tasks is easier for my team than supporting full featured python code).

Is there a way to use custom jinja macros inside tasks templating engine?

Eg:

```auto
{% macro domit(value) -%}

```

```auto
{{ value if value else omit }}

```

```auto
{%- endmacro %}

```

then:

- script: runme.sh  
args:  
creates: “{{ domit(my\_var) }}”

---

<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:** [May 6, 2019, 6:16pm UTC](https://forum.ansible.com/t/using-jinja-macros-in-tasks-templates/30272/2 "2019-05-06T18:16:36Z")

</div>

You can, but it has to be inline with the template where it is used. As such, it is not very useful, since it cannot be reused.

As such, our recommendation is to create custom filter plugins instead of using macros.
