Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
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
edx
configuration
Commits
0a2447d2
Commit
0a2447d2
authored
May 14, 2015
by
Feanil Patel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a new filter to the util map module.
parent
91c9bf45
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
1 deletions
+30
-1
playbooks/library/util_map
+30
-1
No files found.
playbooks/library/util_map
View file @
0a2447d2
...
...
@@ -103,10 +103,37 @@ def zip_to_dict(module, input, key_key, value_key):
module
.
exit_json
(
function_output
=
results
)
def
zip_to_list
(
module
,
input
,
key
):
"""
Takes an array of dicts and flattens it to a single list by extracting the value
of a provided key as an item in the new list.
For example, the input list of dicts like
[{'name':'fred', 'id':'123'},{'name':'bill', 'id':'321'}]
with an args array of ['name']
would return
['fred','bill']
:param input: an array of dicts, typically the results of an ansible module
:param key: a key into the input dict returning a value to be used as an item in the flattend list
:return: the flattened list
"""
results
=
[]
for
item
in
input
:
results
.
append
(
item
[
key
])
module
.
exit_json
(
function_output
=
results
)
def
main
():
arg_spec
=
dict
(
function
=
dict
(
required
=
True
,
choices
=
[
'zip_to_dict'
,
'flatten'
]
),
function
=
dict
(
required
=
True
,
type
=
'str'
),
input
=
dict
(
required
=
True
,
type
=
'str'
),
args
=
dict
(
required
=
False
,
type
=
'list'
),
)
...
...
@@ -122,6 +149,8 @@ def main():
zip_to_dict
(
module
,
input
,
*
args
)
elif
target
==
'flatten'
:
flatten
(
module
,
input
)
elif
target
==
'zip_to_list'
:
zip_to_list
(
module
,
input
,
*
args
)
else
:
raise
NotImplemented
(
"Function {0} is not implemented."
.
format
(
target
))
...
...
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