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
0edaa6f7
Commit
0edaa6f7
authored
Nov 20, 2014
by
Brian Coca
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9270 from bcoca/do_the_shuffle
added new 'shuffle' filter
parents
11b63410
b592d765
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
docsite/rst/playbooks_variables.rst
+14
-0
lib/ansible/runner/filter_plugins/core.py
+10
-2
No files found.
docsite/rst/playbooks_variables.rst
View file @
0edaa6f7
...
...
@@ -297,6 +297,20 @@ Get a random number from 1 to 100 but in steps of 10::
{{ 100 |random(start=1, step=10) }} => 51
Shuffle Filter
--------------
.. versionadded:: 1.8
This filter will randomize an existing list, giving a differnt order every invocation.
To get a random list from an existing list::
{{ ['a','b','c']|shuffle }} => ['c','a','b']
{{ ['a','b','c']|shuffle }} => ['b','c','a']
note that when used with a non 'listable' item it is a noop, otherwise it always returns a list
.. _other_useful_filters:
Other Useful Filters
...
...
lib/ansible/runner/filter_plugins/core.py
View file @
0edaa6f7
...
...
@@ -28,7 +28,7 @@ import operator as py_operator
from
ansible
import
errors
from
ansible.utils
import
md5s
,
checksum_s
from
distutils.version
import
LooseVersion
,
StrictVersion
from
random
import
SystemRandom
from
random
import
SystemRandom
,
shuffle
from
jinja2.filters
import
environmentfilter
...
...
@@ -235,6 +235,13 @@ def rand(environment, end, start=None, step=None):
else
:
raise
errors
.
AnsibleFilterError
(
'random can only be used on sequences and integers'
)
def
randomize_list
(
mylist
):
try
:
mylist
=
list
(
mylist
)
shuffle
(
mylist
)
except
:
pass
return
mylist
class
FilterModule
(
object
):
''' Ansible core jinja2 filters '''
...
...
@@ -310,6 +317,7 @@ class FilterModule(object):
# version comparison
'version_compare'
:
version_compare
,
# random
numbers
# random
stuff
'random'
:
rand
,
'shuffle'
:
randomize_list
,
}
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