mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Fix collision in random filter name by merging functionality
Merges the functionality of the original jinja2 random filter with the one we provide. Fixes #7113
This commit is contained in:
@@ -181,9 +181,20 @@ def version_compare(value, version, operator='eq', strict=False):
|
||||
except Exception, e:
|
||||
raise errors.AnsibleFilterError('Version comparison: %s' % e)
|
||||
|
||||
def rand(end, start=0, step=1):
|
||||
def rand(end, start=None, step=None):
|
||||
r = SystemRandom()
|
||||
return r.randrange(start, end, step)
|
||||
if isinstance(end, (int, long)):
|
||||
if not start:
|
||||
start = 0
|
||||
if not step:
|
||||
step = 1
|
||||
return r.randrange(start, end, step)
|
||||
elif hasattr(end, '__iter__'):
|
||||
if start or step:
|
||||
raise errors.AnsibleFilterError('start and step can only be used with integer values')
|
||||
return r.choice(end)
|
||||
else:
|
||||
raise errors.AnsibleFilterError('random can only be used on sequences and integers')
|
||||
|
||||
class FilterModule(object):
|
||||
''' Ansible core jinja2 filters '''
|
||||
|
||||
Reference in New Issue
Block a user