Skip to content

Commit

Permalink
password: Add example to generate random string (ansible#71144)
Browse files Browse the repository at this point in the history
Password lookup can be used to generate random string
with desired length. This is useful in various scenarios.

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
  • Loading branch information
Akasurde committed Aug 8, 2020
1 parent 3f22f79 commit 501f30d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ansible/plugins/lookup/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- Define comma separated list of names that compose a custom character set in the generated passwords.
- 'By default generated passwords contain a random mix of upper and lowercase ASCII letters, the numbers 0-9 and punctuation (". , : - _").'
- "They can be either parts of Python's string module attributes (ascii_letters,digits, etc) or are used literally ( :, -)."
- "Other valid values include 'ascii_lowercase', 'ascii_uppercase', 'digits', 'hexdigits', 'octdigits', 'printable', 'punctuation' and 'whitespace'."
- "To enter comma use two commas ',,' somewhere - preferably at the end. Quotes and double quotes are not supported."
type: string
length:
Expand Down Expand Up @@ -84,6 +85,10 @@
name: "{{ client }}"
password: "{{ lookup('password', '/tmp/passwordfile chars=ascii_letters,digits,hexdigits,punctuation') }}"
priv: "{{ client }}_{{ tier }}_{{ role }}.*:ALL"
- name: create lowercase 8 character name for Kubernetes pod name
set_fact:
random_pod_name: "web-{{ lookup('password', '/dev/null chars=ascii_lowercase,digits length=8') }}"
"""

RETURN = """
Expand Down

0 comments on commit 501f30d

Please sign in to comment.