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
6e99023c
Commit
6e99023c
authored
Jul 13, 2015
by
Alejandro Guirao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed to support Ansible v2
parent
8efc42d9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
lib/ansible/plugins/lookup/shelvefile.py
+18
-14
No files found.
lib/ansible/plugins/lookup/shelvefile.py
View file @
6e99023c
...
...
@@ -14,12 +14,16 @@
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
import
shelve
import
os
from
ansible
import
utils
,
errors
class
LookupModule
(
object
):
from
ansible.errors
import
AnsibleError
from
ansible.plugins.lookup
import
LookupBase
class
LookupModule
(
LookupBase
):
def
__init__
(
self
,
basedir
=
None
,
**
kwargs
):
self
.
basedir
=
basedir
...
...
@@ -33,17 +37,17 @@ class LookupModule(object):
d
.
close
()
return
res
def
run
(
self
,
terms
,
inject
=
None
,
**
kwargs
):
terms
=
utils
.
listify_lookup_plugin_terms
(
terms
,
self
.
basedir
,
inject
)
ret
=
[]
def
run
(
self
,
terms
,
variables
=
None
,
**
kwargs
):
if
not
isinstance
(
terms
,
list
):
terms
=
[
terms
]
ret
=
[]
for
term
in
terms
:
playbook_path
=
None
relative_path
=
None
paramvals
=
{
"file"
:
None
,
"key"
:
None
}
params
=
term
.
split
()
...
...
@@ -55,27 +59,27 @@ class LookupModule(object):
except
(
ValueError
,
AssertionError
),
e
:
# In case "file" or "key" are not present
raise
errors
.
AnsibleError
(
e
)
raise
AnsibleError
(
e
)
file
=
paramvals
[
'file'
]
key
=
paramvals
[
'key'
]
basedir_path
=
utils
.
path_dwim
(
self
.
basedir
,
file
)
basedir_path
=
self
.
_loader
.
path_dwim
(
file
)
# Search also in the role/files directory and in the playbook directory
if
'
_original_file'
in
inject
:
relative_path
=
utils
.
path_dwim_relative
(
inject
[
'_original_file'
],
'files'
,
file
,
self
.
basedir
,
check
=
Fals
e
)
if
'playbook_dir'
in
inject
:
playbook_path
=
os
.
path
.
join
(
inject
[
'playbook_dir'
]
,
file
)
if
'
role_path'
in
variables
:
relative_path
=
self
.
_loader
.
path_dwim_relative
(
variables
[
'role_path'
],
'files'
,
fil
e
)
if
'playbook_dir'
in
variables
:
playbook_path
=
self
.
_loader
.
path_dwim_relative
(
variables
[
'playbook_dir'
],
'files'
,
file
)
for
path
in
(
basedir_path
,
relative_path
,
playbook_path
):
if
path
and
os
.
path
.
exists
(
path
):
res
=
self
.
read_shelve
(
path
,
key
)
if
res
is
None
:
raise
errors
.
AnsibleError
(
"Key
%
s not found in shelve file
%
s"
%
(
key
,
file
))
raise
AnsibleError
(
"Key
%
s not found in shelve file
%
s"
%
(
key
,
file
))
# Convert the value read to string
ret
.
append
(
str
(
res
))
break
else
:
raise
errors
.
AnsibleError
(
"Could not locate shelve file in lookup:
%
s"
%
file
)
raise
AnsibleError
(
"Could not locate shelve file in lookup:
%
s"
%
file
)
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