# Create variables in hash

**URL:** <https://forum.ansible.com/t/create-variables-in-hash/29531>\
**Category:** Ansible Project\
**Created:** [January 25, 2019, 6:10pm UTC](https://forum.ansible.com/t/create-variables-in-hash/29531 "2019-01-25T18:10:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Tomelin](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rafael\_Tomelin](https://forum.ansible.com/u/Rafael_Tomelin)\
**Post date:** [January 25, 2019, 6:10pm UTC](https://forum.ansible.com/t/create-variables-in-hash/29531/1 "2019-01-25T18:10:41Z")

</div>

Hi dear,

How can create variables in hash, example:

---

<div class="post-metadata">

**Author:** ![mboncalo](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mboncalo](https://forum.ansible.com/u/mboncalo)\
**Post date:** [January 25, 2019, 7:22pm UTC](https://forum.ansible.com/t/create-variables-in-hash/29531/2 "2019-01-25T19:22:57Z")

</div>

key: {{ my\_key | hash('sha1') }} ...

Hashing filters

New in version 1.9.

To get the sha1 hash of a string:

{{ 'test1' | hash('sha1') }}

To get the md5 hash of a string:

{{ 'test1' | hash('md5') }}

Get a string checksum:

{{ 'test2' | checksum }}

Other hashes (platform dependent):

{{ 'test2' | hash('blowfish') }}

To get a sha512 password hash (random salt):

{{ 'passwordsaresecret' | password\_hash('sha512') }}

To get a sha256 password hash with a specific salt:

{{ 'secretpassword' | password\_hash('sha256', 'mysecretsalt') }}

An idempotent method to generate unique hashes per system is to use a  
salt that is consistent between runs:

{{ 'secretpassword' | password\_hash('sha512', 65534 |  
random(seed=inventory\_hostname) | string) }}

---

<div class="post-metadata">

**Author:** ![Rafael\_Tomelin](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rafael\_Tomelin](https://forum.ansible.com/u/Rafael_Tomelin)\
**Post date:** [January 28, 2019, 4:43pm UTC](https://forum.ansible.com/t/create-variables-in-hash/29531/3 "2019-01-28T16:43:07Z")

</div>

Hi, thanks

Resolved
