Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
bfb25f4f
Commit
bfb25f4f
authored
Apr 10, 2014
by
jctanner
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6917 from bcoca/random_filter_clean
simple random filter
parents
33099b9b
80cd217e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
docsite/rst/playbooks_variables.rst
+21
-0
lib/ansible/runner/filter_plugins/core.py
+8
-0
No files found.
docsite/rst/playbooks_variables.rst
View file @
bfb25f4f
...
...
@@ -234,6 +234,27 @@ be used. The default is ``False``, and if set as ``True`` will use more strict
{{ sample_version_var | version_compare('1.0', operator='lt', strict=True) }}
.. _random_filter
Random Number Filter
--------------------------
.. versionadded:: 1.6
To get a random number from 0 to supplied end::
{{ 59 |random}} * * * * root /script/from/cron
Get a random number from 0 to 100 but in steps of 10::
{{ 100 |random(step=10) }} => 70
Get a random number from 1 to 100 but in steps of 10::
{{ 100 |random(1, 10) }} => 31
{{ 100 |random(start=1, step=10) }} => 51
.. _other_useful_filters:
Other Useful Filters
...
...
lib/ansible/runner/filter_plugins/core.py
View file @
bfb25f4f
...
...
@@ -27,6 +27,7 @@ import operator as py_operator
from
ansible
import
errors
from
ansible.utils
import
md5s
from
distutils.version
import
LooseVersion
,
StrictVersion
from
random
import
SystemRandom
def
to_nice_yaml
(
*
a
,
**
kw
):
'''Make verbose, human readable yaml'''
...
...
@@ -180,6 +181,10 @@ 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
):
r
=
SystemRandom
()
return
r
.
randrange
(
start
,
end
,
step
)
class
FilterModule
(
object
):
''' Ansible core jinja2 filters '''
...
...
@@ -245,5 +250,8 @@ class FilterModule(object):
# version comparison
'version_compare'
:
version_compare
,
# random numbers
'random'
:
rand
,
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment