Ansible has a very simple ad-hoc command for this
1ansible all -i localhost, -m debug -a "msg={{ 'mypassword' | password_hash('sha512', 'mysecretsalt') }}"
We can also use the Passlib library of Python, e.g
1python -c "from passlib.hash import sha512_crypt; import getpass; print(sha512_crypt.using(rounds=5000).hash(getpass.getpass()))"
On top of this, we should also avoid storing raw passwords in playbook
or host_vars, instead, we should use integrated methods to generate
a hash version of a password.