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
4f9af7ef
Commit
4f9af7ef
authored
Sep 09, 2013
by
Serge van Ginderachter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
subelements lookup plugin
parent
b3c0e3e4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
lib/ansible/runner/lookup_plugins/subelements.py
+61
-0
No files found.
lib/ansible/runner/lookup_plugins/subelements.py
0 → 100644
View file @
4f9af7ef
# (c) 2013, Serge van Ginderachter <serge@vanginderachter.be>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import
ansible.utils
as
utils
import
ansible.errors
as
errors
class
LookupModule
(
object
):
def
__init__
(
self
,
basedir
=
None
,
**
kwargs
):
self
.
basedir
=
basedir
def
run
(
self
,
terms
,
inject
=
None
,
**
kwargs
):
terms
=
utils
.
listify_lookup_plugin_terms
(
terms
,
self
.
basedir
,
inject
)
terms
[
0
]
=
utils
.
listify_lookup_plugin_terms
(
terms
[
0
],
self
.
basedir
,
inject
)
if
not
isinstance
(
terms
,
list
)
or
not
len
(
terms
)
==
2
:
raise
errors
.
AnsibleError
(
"subelements lookup expects a list of two items, first a dict or a list, and second a string"
)
terms
[
0
]
=
utils
.
listify_lookup_plugin_terms
(
terms
[
0
],
self
.
basedir
,
inject
)
if
not
isinstance
(
terms
[
0
],
(
list
,
dict
))
or
not
isinstance
(
terms
[
1
],
basestring
):
raise
errors
.
AnsibleError
(
"subelements lookup expects a list of two items, first a dict or a list, and second a string"
)
if
isinstance
(
terms
[
0
],
dict
):
# convert to list:
elementlist
=
[]
for
key
in
terms
[
0
]
.
iterkeys
():
elementlist
.
append
(
terms
[
0
][
key
])
else
:
elementlist
=
terms
[
0
]
subelement
=
terms
[
1
]
ret
=
[]
for
item0
in
elementlist
:
if
not
isinstance
(
item0
,
dict
):
raise
errors
.
AnsibleError
(
"subelements lookup expects a dictionary, got '
%
s'"
%
item0
)
if
not
subelement
in
item0
:
raise
errors
.
AnsibleError
(
"could not find '
%
s' key in iterated item '
%
s'"
%
(
subelement
,
item0
))
if
not
isinstance
(
item0
[
subelement
],
list
):
raise
errors
.
AnsibleError
(
"the key
%
s should point to a list, got '
%
s'"
%
(
subelement
,
item0
[
subelement
]))
sublist
=
item0
.
pop
(
subelement
,
[])
for
item1
in
sublist
:
ret
.
append
((
item0
,
item1
))
return
ret
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