Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #7242/c3fd14e1 backport][stable-7] Ignore similar chars in random_string #7292

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/7242_ignore_similar_chars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- random_string - added new ``ignore_similar_chars`` and ``similar_chars`` option to ignore certain chars (https://github.com/ansible-collections/community.general/pull/7242).
21 changes: 21 additions & 0 deletions plugins/lookup/random_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@
- Override all values of O(numbers), O(upper), O(lower), and O(special) with
the given list of characters.
type: str
ignore_similar_chars:
description:
- Ignore similar characters, such as V(l) and V(1), or V(O) and V(0).
- These characters can be configured in O(similar_chars).
default: false
type: bool
version_added: 7.5.0
similar_chars:
description:
- Overide a list of characters not to be use in the string.
default: "il1LoO0"
type: str
version_added: 7.5.0
base64:
description:
- Returns base64 encoded string.
Expand Down Expand Up @@ -173,9 +186,17 @@ def run(self, terms, variables=None, **kwargs):
length = self.get_option("length")
base64_flag = self.get_option("base64")
override_all = self.get_option("override_all")
ignore_similar_chars = self.get_option("ignore_similar_chars")
similar_chars = self.get_option("similar_chars")
values = ""
available_chars_set = ""

if ignore_similar_chars:
number_chars = "".join([sc for sc in number_chars if sc not in similar_chars])
lower_chars = "".join([sc for sc in lower_chars if sc not in similar_chars])
upper_chars = "".join([sc for sc in upper_chars if sc not in similar_chars])
special_chars = "".join([sc for sc in special_chars if sc not in similar_chars])

if override_all:
# Override all the values
available_chars_set = override_all
Expand Down