From 90dd698b866c7cab4e1269d93dcc28d0057262c7 Mon Sep 17 00:00:00 2001 From: Daniel Linder Date: Thu, 28 Sep 2017 14:59:10 -0500 Subject: [PATCH] Example of idempotent (pseudo-)random() usage. (#31048) Add note to use idempotent random() seed based on inventory_hostname. --- docs/docsite/rst/playbooks_filters.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/docsite/rst/playbooks_filters.rst b/docs/docsite/rst/playbooks_filters.rst index 3b00c92b7ac..30b7029f6f7 100644 --- a/docs/docsite/rst/playbooks_filters.rst +++ b/docs/docsite/rst/playbooks_filters.rst @@ -451,7 +451,10 @@ To get a sha512 password hash (random salt):: 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) }} Hash types available depend on the master system running ansible, 'hash' depends on hashlib password_hash depends on passlib (http://passlib.readthedocs.io/en/stable/lib/passlib.hash.html).