# How to use variables in a Jinja2 filter?

**URL:** <https://forum.ansible.com/t/how-to-use-variables-in-a-jinja2-filter/22753>\
**Category:** Ansible Project\
**Created:** [October 9, 2016, 7:18pm UTC](https://forum.ansible.com/t/how-to-use-variables-in-a-jinja2-filter/22753 "2016-10-09T19:18:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Li](https://avatars.discourse-cdn.com/v4/letter/d/e495f1/32.png) [@David\_Li](https://forum.ansible.com/u/David_Li)\
**Post date:** [October 9, 2016, 7:18pm UTC](https://forum.ansible.com/t/how-to-use-variables-in-a-jinja2-filter/22753/1 "2016-10-09T19:18:27Z")

</div>

Hi,

I am trying to create an user with password hash filter like this:

- name: Create a user  
user:  
name: abc  
group: xyz  
password: {{ ‘mypass’|password\_hash(‘sha256’, ‘mysalt’) }}

This works!  
Now I would like to use variables in place of ‘mypass’ and ‘mysault’ that are defined in vars/main.yml (encrypted by vault)

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 10, 2016, 4:19pm UTC](https://forum.ansible.com/t/how-to-use-variables-in-a-jinja2-filter/22753/2 "2016-10-10T16:19:08Z")

</div>

Curly brackets doesn't stack, just use the variable directly without quotes.

password: "{{ password | password\_hash('sha256', password\_sault) }}"
