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
d34e320e
Commit
d34e320e
authored
Dec 17, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1733 from dhozac/lookup-list
Make all lookup plugins accept lists as arguments
parents
04195e20
b73016b8
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
102 additions
and
69 deletions
+102
-69
lib/ansible/runner/lookup_plugins/dnstxt.py
+20
-16
lib/ansible/runner/lookup_plugins/env.py
+7
-3
lib/ansible/runner/lookup_plugins/file.py
+9
-4
lib/ansible/runner/lookup_plugins/fileglob.py
+10
-7
lib/ansible/runner/lookup_plugins/items.py
+3
-4
lib/ansible/runner/lookup_plugins/lines.py
+11
-6
lib/ansible/runner/lookup_plugins/pipe.py
+11
-6
lib/ansible/runner/lookup_plugins/redis_kv.py
+25
-21
lib/ansible/runner/lookup_plugins/template.py
+6
-2
No files found.
lib/ansible/runner/lookup_plugins/dnstxt.py
View file @
d34e320e
...
@@ -41,20 +41,24 @@ class LookupModule(object):
...
@@ -41,20 +41,24 @@ class LookupModule(object):
raise
errors
.
AnsibleError
(
"Can't LOOKUP(dnstxt): module dns.resolver is not installed"
)
raise
errors
.
AnsibleError
(
"Can't LOOKUP(dnstxt): module dns.resolver is not installed"
)
def
run
(
self
,
terms
,
**
kwargs
):
def
run
(
self
,
terms
,
**
kwargs
):
if
isinstance
(
terms
,
basestring
):
terms
=
[
terms
]
ret
=
[]
for
term
in
terms
:
domain
=
term
.
split
()[
0
]
string
=
[]
try
:
answers
=
dns
.
resolver
.
query
(
domain
,
'TXT'
)
for
rdata
in
answers
:
s
=
rdata
.
to_text
()
string
.
append
(
s
[
1
:
-
1
])
# Strip outside quotes on TXT rdata
domain
=
terms
.
split
()[
0
]
except
dns
.
resolver
.
NXDOMAIN
:
string
=
[]
string
=
'NXDOMAIN'
try
:
except
dns
.
resolver
.
Timeout
:
answers
=
dns
.
resolver
.
query
(
domain
,
'TXT'
)
string
=
''
for
rdata
in
answers
:
except
dns
.
exception
.
DNSException
as
e
:
s
=
rdata
.
to_text
()
raise
errors
.
AnsibleError
(
"dns.resolver unhandled exception"
,
e
)
string
.
append
(
s
[
1
:
-
1
])
# Strip outside quotes on TXT rdata
ret
.
append
(
''
.
join
(
string
))
except
dns
.
resolver
.
NXDOMAIN
:
return
ret
string
=
'NXDOMAIN'
except
dns
.
resolver
.
Timeout
:
string
=
''
except
dns
.
exception
.
DNSException
as
e
:
raise
errors
.
AnsibleError
(
"dns.resolver unhandled exception"
,
e
)
return
''
.
join
(
string
)
lib/ansible/runner/lookup_plugins/env.py
View file @
d34e320e
...
@@ -24,6 +24,10 @@ class LookupModule(object):
...
@@ -24,6 +24,10 @@ class LookupModule(object):
self
.
basedir
=
basedir
self
.
basedir
=
basedir
def
run
(
self
,
terms
,
**
kwargs
):
def
run
(
self
,
terms
,
**
kwargs
):
if
isinstance
(
terms
,
basestring
):
var
=
terms
.
split
()[
0
]
terms
=
[
terms
]
return
os
.
getenv
(
var
,
''
)
ret
=
[]
for
term
in
terms
:
var
=
term
.
split
()[
0
]
ret
.
append
(
os
.
getenv
(
var
,
''
))
return
ret
lib/ansible/runner/lookup_plugins/file.py
View file @
d34e320e
...
@@ -24,7 +24,12 @@ class LookupModule(object):
...
@@ -24,7 +24,12 @@ class LookupModule(object):
self
.
basedir
=
basedir
self
.
basedir
=
basedir
def
run
(
self
,
terms
,
**
kwargs
):
def
run
(
self
,
terms
,
**
kwargs
):
path
=
utils
.
path_dwim
(
self
.
basedir
,
terms
)
if
isinstance
(
terms
,
basestring
):
if
not
os
.
path
.
exists
(
path
):
terms
=
[
terms
]
raise
errors
.
AnsibleError
(
"
%
s does not exist"
%
path
)
ret
=
[]
return
[
open
(
path
)
.
read
()
.
rstrip
()]
for
term
in
terms
:
path
=
utils
.
path_dwim
(
self
.
basedir
,
term
)
if
not
os
.
path
.
exists
(
path
):
raise
errors
.
AnsibleError
(
"
%
s does not exist"
%
path
)
ret
.
append
(
open
(
path
)
.
read
()
.
rstrip
())
return
ret
lib/ansible/runner/lookup_plugins/fileglob.py
View file @
d34e320e
...
@@ -25,10 +25,13 @@ class LookupModule(object):
...
@@ -25,10 +25,13 @@ class LookupModule(object):
self
.
basedir
=
basedir
self
.
basedir
=
basedir
def
run
(
self
,
terms
,
**
kwargs
):
def
run
(
self
,
terms
,
**
kwargs
):
dwimterms
=
utils
.
path_dwim
(
self
.
basedir
,
terms
)
if
isinstance
(
terms
,
basestring
):
# This skips whatever prefix the dwim added, leaving just the filename for the item
terms
=
[
terms
]
dwim_prefix_len
=
len
(
dwimterms
)
-
len
(
terms
)
ret
=
[]
return
[
f
[
dwim_prefix_len
:]
for
f
in
glob
.
glob
(
dwimterms
)
if
os
.
path
.
isfile
(
f
)
]
for
term
in
terms
:
dwimterms
=
utils
.
path_dwim
(
self
.
basedir
,
term
)
# This skips whatever prefix the dwim added, leaving just the filename for the item
dwim_prefix_len
=
len
(
dwimterms
)
-
len
(
term
)
ret
.
extend
([
f
[
dwim_prefix_len
:]
for
f
in
glob
.
glob
(
dwimterms
)
if
os
.
path
.
isfile
(
f
)
])
return
ret
lib/ansible/runner/lookup_plugins/items.py
View file @
d34e320e
...
@@ -21,7 +21,6 @@ class LookupModule(object):
...
@@ -21,7 +21,6 @@ class LookupModule(object):
pass
pass
def
run
(
self
,
terms
,
**
kwargs
):
def
run
(
self
,
terms
,
**
kwargs
):
return
terms
if
isinstance
(
terms
,
basestring
):
terms
=
[
terms
]
return
[
term
for
term
in
terms
]
lib/ansible/runner/lookup_plugins/lines.py
View file @
d34e320e
...
@@ -24,9 +24,14 @@ class LookupModule(object):
...
@@ -24,9 +24,14 @@ class LookupModule(object):
self
.
basedir
=
basedir
self
.
basedir
=
basedir
def
run
(
self
,
terms
,
**
kwargs
):
def
run
(
self
,
terms
,
**
kwargs
):
p
=
subprocess
.
Popen
(
terms
,
cwd
=
self
.
basedir
,
shell
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
if
isinstance
(
terms
,
basestring
):
(
stdout
,
stderr
)
=
p
.
communicate
()
terms
=
[
terms
]
if
p
.
returncode
==
0
:
ret
=
[]
return
stdout
.
splitlines
()
for
term
in
terms
:
else
:
p
=
subprocess
.
Popen
(
term
,
cwd
=
self
.
basedir
,
shell
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
raise
errors
.
AnsibleError
(
"lookup_plugin.lines(
%
s) returned
%
d"
%
(
terms
,
p
.
returncode
))
(
stdout
,
stderr
)
=
p
.
communicate
()
if
p
.
returncode
==
0
:
ret
.
extend
(
stdout
.
splitlines
())
else
:
raise
errors
.
AnsibleError
(
"lookup_plugin.lines(
%
s) returned
%
d"
%
(
term
,
p
.
returncode
))
return
ret
lib/ansible/runner/lookup_plugins/pipe.py
View file @
d34e320e
...
@@ -24,9 +24,14 @@ class LookupModule(object):
...
@@ -24,9 +24,14 @@ class LookupModule(object):
self
.
basedir
=
basedir
self
.
basedir
=
basedir
def
run
(
self
,
terms
,
**
kwargs
):
def
run
(
self
,
terms
,
**
kwargs
):
p
=
subprocess
.
Popen
(
terms
,
cwd
=
self
.
basedir
,
shell
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
if
isinstance
(
terms
,
basestring
):
(
stdout
,
stderr
)
=
p
.
communicate
()
terms
=
[
terms
]
if
p
.
returncode
==
0
:
ret
=
[]
return
[
stdout
.
rstrip
()]
for
term
in
terms
:
else
:
p
=
subprocess
.
Popen
(
term
,
cwd
=
self
.
basedir
,
shell
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
raise
errors
.
AnsibleError
(
"lookup_plugin.pipe(
%
s) returned
%
d"
%
(
terms
,
p
.
returncode
))
(
stdout
,
stderr
)
=
p
.
communicate
()
if
p
.
returncode
==
0
:
ret
.
append
(
stdout
.
rstrip
())
else
:
raise
errors
.
AnsibleError
(
"lookup_plugin.pipe(
%
s) returned
%
d"
%
(
term
,
p
.
returncode
))
return
ret
lib/ansible/runner/lookup_plugins/redis_kv.py
View file @
d34e320e
...
@@ -40,28 +40,32 @@ class LookupModule(object):
...
@@ -40,28 +40,32 @@ class LookupModule(object):
raise
errors
.
AnsibleError
(
"Can't LOOKUP(redis_kv): module redis is not installed"
)
raise
errors
.
AnsibleError
(
"Can't LOOKUP(redis_kv): module redis is not installed"
)
def
run
(
self
,
terms
,
**
kwargs
):
def
run
(
self
,
terms
,
**
kwargs
):
if
isinstance
(
terms
,
basestring
):
terms
=
[
terms
]
ret
=
[]
for
term
in
terms
:
(
url
,
key
)
=
term
.
split
(
','
)
if
url
==
""
:
url
=
'redis://localhost:6379'
(
url
,
key
)
=
terms
.
split
(
','
)
# urlsplit on Python 2.6.1 is broken. Hmm. Probably also the reason
if
url
==
""
:
# Redis' from_url() doesn't work here.
url
=
'redis://localhost:6379'
# urlsplit on Python 2.6.1 is broken. Hmm. Probably also the reason
p
=
'(?P<scheme>[^:]+)://?(?P<host>[^:/ ]+).?(?P<port>[0-9]*).*'
# Redis' from_url() doesn't work here.
p
=
'(?P<scheme>[^:]+)://?(?P<host>[^:/ ]+).?(?P<port>[0-9]*).*'
try
:
m
=
re
.
search
(
p
,
url
)
host
=
m
.
group
(
'host'
)
port
=
int
(
m
.
group
(
'port'
))
except
AttributeError
:
raise
errors
.
AnsibleError
(
"Bad URI in redis lookup"
)
try
:
try
:
m
=
re
.
search
(
p
,
url
)
conn
=
redis
.
Redis
(
host
=
host
,
port
=
port
)
host
=
m
.
group
(
'host'
)
res
=
conn
.
get
(
key
)
port
=
int
(
m
.
group
(
'port'
))
if
res
is
None
:
except
AttributeError
:
res
=
""
raise
errors
.
AnsibleError
(
"Bad URI in redis lookup"
)
ret
.
append
(
res
)
except
:
try
:
ret
.
append
(
""
)
# connection failed or key not found
conn
=
redis
.
Redis
(
host
=
host
,
port
=
port
)
return
ret
res
=
conn
.
get
(
key
)
if
res
is
None
:
res
=
""
return
res
except
:
return
""
# connection failed or key not found
lib/ansible/runner/lookup_plugins/template.py
View file @
d34e320e
...
@@ -23,5 +23,9 @@ class LookupModule(object):
...
@@ -23,5 +23,9 @@ class LookupModule(object):
self
.
basedir
=
basedir
self
.
basedir
=
basedir
def
run
(
self
,
terms
,
inject
=
None
,
**
kwargs
):
def
run
(
self
,
terms
,
inject
=
None
,
**
kwargs
):
return
utils
.
template_from_file
(
self
.
basedir
,
terms
,
inject
)
if
isinstance
(
terms
,
basestring
):
terms
=
[
terms
]
ret
=
[]
for
term
in
terms
:
ret
.
append
(
utils
.
template_from_file
(
self
.
basedir
,
term
,
inject
))
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