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
b678b982
Commit
b678b982
authored
Jul 22, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplified and normalized lookup search path behaviour
parent
857f584e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
26 deletions
+33
-26
lib/ansible/plugins/lookup/csvfile.py
+8
-3
lib/ansible/plugins/lookup/file.py
+13
-19
lib/ansible/plugins/lookup/template.py
+12
-4
No files found.
lib/ansible/plugins/lookup/csvfile.py
View file @
b678b982
...
...
@@ -46,6 +46,12 @@ class LookupModule(LookupBase):
terms
=
[
terms
]
ret
=
[]
if
'role_path'
in
variables
:
basedir
=
variables
[
'role_path'
]
else
:
basedir
=
self
.
_loader
.
get_basedir
()
for
term
in
terms
:
params
=
term
.
split
()
key
=
params
[
0
]
...
...
@@ -69,9 +75,8 @@ class LookupModule(LookupBase):
if
paramvals
[
'delimiter'
]
==
'TAB'
:
paramvals
[
'delimiter'
]
=
"
\t
"
path
=
self
.
_loader
.
path_dwim
(
paramvals
[
'file'
])
var
=
self
.
read_csv
(
path
,
key
,
paramvals
[
'delimiter'
],
paramvals
[
'default'
],
paramvals
[
'col'
])
lookupfile
=
self
.
_loader
.
path_dwim_relative
(
basedir
,
'files'
,
term
)
var
=
self
.
read_csv
(
lookupfile
,
key
,
paramvals
[
'delimiter'
],
paramvals
[
'default'
],
paramvals
[
'col'
])
if
var
is
not
None
:
if
type
(
var
)
is
list
:
for
v
in
var
:
...
...
lib/ansible/plugins/lookup/file.py
View file @
b678b982
...
...
@@ -31,10 +31,13 @@ class LookupModule(LookupBase):
terms
=
[
terms
]
ret
=
[]
if
'role_path'
in
variables
:
basedir
=
variables
[
'role_path'
]
else
:
basedir
=
self
.
_loader
.
get_basedir
()
for
term
in
terms
:
basedir_path
=
self
.
_loader
.
path_dwim
(
term
)
relative_path
=
None
playbook_path
=
None
# Special handling of the file lookup, used primarily when the
# lookup is done from a role. If the file isn't found in the
...
...
@@ -42,23 +45,14 @@ class LookupModule(LookupBase):
# role/files/ directory, and finally the playbook directory
# itself (which will be relative to the current working dir)
if
'role_path'
in
variables
:
relative_path
=
self
.
_loader
.
path_dwim_relative
(
variables
[
'role_path'
],
'files'
,
term
)
# FIXME: the original file stuff still needs to be worked out, but the
# playbook_dir stuff should be able to be removed as it should
# be covered by the fact that the loader contains that info
if
'playbook_dir'
in
variables
:
playbook_path
=
self
.
_loader
.
path_dwim_relative
(
variables
[
'playbook_dir'
],
'files'
,
term
)
for
path
in
(
basedir_path
,
relative_path
,
playbook_path
):
try
:
contents
,
show_data
=
self
.
_loader
.
_get_file_contents
(
path
)
lookupfile
=
self
.
_loader
.
path_dwim_relative
(
basedir
,
'files'
,
term
)
try
:
if
lookupfile
:
contents
,
show_data
=
self
.
_loader
.
_get_file_contents
(
lookupfile
)
ret
.
append
(
contents
.
rstrip
())
break
except
AnsibleParserError
:
continue
else
:
else
:
raise
AnsibleParserError
()
except
AnsibleParserError
:
raise
AnsibleError
(
"could not locate file in lookup:
%
s"
%
term
)
return
ret
lib/ansible/plugins/lookup/template.py
View file @
b678b982
...
...
@@ -30,16 +30,24 @@ class LookupModule(LookupBase):
if
not
isinstance
(
terms
,
list
):
terms
=
[
terms
]
ret
=
[]
templar
=
Templar
(
loader
=
self
.
_loader
,
variables
=
variables
)
ret
=
[]
if
'role_path'
in
variables
:
basedir
=
variables
[
'role_path'
]
else
:
basedir
=
self
.
_loader
.
get_basedir
()
for
term
in
terms
:
path
=
self
.
_loader
.
path_dwim
(
term
)
if
os
.
path
.
exists
(
path
):
with
open
(
path
,
'r'
)
as
f
:
lookupfile
=
self
.
_loader
.
path_dwim_relative
(
basedir
,
'templates'
,
term
)
if
lookupfile
and
os
.
path
.
exists
(
lookupfile
):
with
open
(
lookupfile
,
'r'
)
as
f
:
template_data
=
f
.
read
()
res
=
templar
.
template
(
template_data
,
preserve_trailing_newlines
=
True
)
ret
.
append
(
res
)
else
:
raise
AnsibleError
(
"the template file
%
s could not be found for the lookup"
%
term
)
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