assign hash type dynamically to password_hash() in ansible

Viewed 135

is it possible to insert a variable into the password_hash() filter? something that would work like this:

password: "{{ 'mypassword' | password_hash('hash_var') }}"

hash_var being md5 or sha256 or sha512

thanks!

1 Answers

Yes. It is possible. For example, both expressions below

    password: "{{ 'mypassword' | password_hash('sha256', 'salt') }}"
    password: "{{ 'mypassword' | password_hash(hash_var, 'salt') }}"
    hash_var: sha256

give the same result

    password: $5$salt$TYJ6ATpIhYy.nairVJIpWv4n5ky/FxBc31yIH5kPE70
Related