how can I encode a given string using ansible?
I'm trying to do this:
echo -n "mypassword" | sha1sum
Q: "Encode a given string."
A: Use hash filter. For example, the command and the filter
- shell: echo -n "mypassword" | sha1sum
register: result
- debug:
var: result.stdout
- set_fact:
pswd: "{{ 'mypassword' | hash('sha1') }}"
- debug:
var: pswd
give the same results
"result.stdout": "91dfd9ddb4198affc5c194cd8ce6d338fde470e2 -"
"pswd": "91dfd9ddb4198affc5c194cd8ce6d338fde470e2"
Q: "Insert the output string into a file."
A: For example, use the template
shell> cat templates/pswd.j2.txt
pswd: {{ pswd }}
- template:
src: pswd.j2.txt
dest: pswd.txt
give
shell> cat pswd.txt
pswd: 91dfd9ddb4198affc5c194cd8ce6d338fde470e2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With