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
30399eda
Commit
30399eda
authored
Sep 08, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use UnsafeProxy for lookup results too
Also fixes a couple of bugs that popped up when using the proxy class
parent
f0411217
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
5 deletions
+37
-5
lib/ansible/executor/task_executor.py
+7
-1
lib/ansible/template/__init__.py
+12
-2
lib/ansible/utils/vars.py
+11
-0
lib/ansible/vars/unsafe_proxy.py
+7
-2
No files found.
lib/ansible/executor/task_executor.py
View file @
30399eda
...
...
@@ -34,6 +34,7 @@ from ansible.playbook.task import Task
from
ansible.template
import
Templar
from
ansible.utils.listify
import
listify_lookup_plugin_terms
from
ansible.utils.unicode
import
to_unicode
from
ansible.utils.vars
import
json_variable_cleaner
from
ansible.utils.debug
import
debug
...
...
@@ -123,7 +124,7 @@ class TaskExecutor:
res
[
'changed'
]
=
False
debug
(
"dumping result to json"
)
result
=
json
.
dumps
(
res
)
result
=
json
.
dumps
(
res
,
default
=
json_variable_cleaner
)
debug
(
"done dumping result, returning"
)
return
result
except
AnsibleError
as
e
:
...
...
@@ -160,6 +161,11 @@ class TaskExecutor:
else
:
raise
AnsibleError
(
"Unexpected failure in finding the lookup named '
%
s' in the available lookup plugins"
%
self
.
_task
.
loop
)
if
items
:
from
ansible.vars.unsafe_proxy
import
UnsafeProxy
for
idx
,
item
in
enumerate
(
items
):
if
item
is
not
None
and
not
isinstance
(
item
,
UnsafeProxy
):
items
[
idx
]
=
UnsafeProxy
(
item
)
return
items
def
_run_loop
(
self
,
items
):
...
...
lib/ansible/template/__init__.py
View file @
30399eda
...
...
@@ -213,8 +213,15 @@ class Templar:
before being sent through the template engine.
'''
# Don't template unsafe variables, instead drop them back down to
# their constituent type.
if
hasattr
(
variable
,
'__UNSAFE__'
):
return
variable
if
isinstance
(
variable
,
unicode
):
return
unicode
(
variable
)
elif
isinstance
(
variable
,
str
):
return
str
(
variable
)
else
:
return
variable
try
:
if
convert_bare
:
...
...
@@ -313,8 +320,11 @@ class Templar:
if
self
.
_fail_on_lookup_errors
:
raise
ran
=
None
if
ran
:
ran
=
","
.
join
(
ran
)
from
ansible.vars.unsafe_proxy
import
UnsafeProxy
ran
=
UnsafeProxy
(
","
.
join
(
ran
))
return
ran
else
:
raise
AnsibleError
(
"lookup plugin (
%
s) not found"
%
name
)
...
...
lib/ansible/utils/vars.py
View file @
30399eda
...
...
@@ -128,3 +128,14 @@ def isidentifier(ident):
return
True
def
json_variable_cleaner
(
obj
):
'''
Used as the default= parameter to json.dumps(), this method helps
clear out UnsafeProxy variables so they can be properly JSON encoded
'''
from
ansible.vars.unsafe_proxy
import
UnsafeProxy
if
isinstance
(
obj
,
UnsafeProxy
):
return
obj
.
_obj
else
:
return
obj
lib/ansible/vars/unsafe_proxy.py
View file @
30399eda
...
...
@@ -59,10 +59,15 @@ class UnsafeProxy(object):
# proxying (special cases)
#
def
__getattribute__
(
self
,
name
):
if
name
==
'__UNSAFE__'
:
if
name
==
'_obj'
:
return
object
.
__getattribute__
(
self
,
"_obj"
)
elif
name
==
'__UNSAFE__'
:
return
True
else
:
return
getattr
(
object
.
__getattribute__
(
self
,
"_obj"
),
name
)
def
__eq__
(
self
,
obj
):
return
object
.
__getattribute__
(
self
,
"_obj"
)
==
obj
def
__delattr__
(
self
,
name
):
delattr
(
object
.
__getattribute__
(
self
,
"_obj"
),
name
)
def
__setattr__
(
self
,
name
,
value
):
...
...
@@ -108,7 +113,7 @@ class UnsafeProxy(object):
namespace
=
{}
for
name
in
cls
.
_special_names
:
if
hasattr
(
theclass
,
name
):
if
hasattr
(
theclass
,
name
)
and
not
hasattr
(
cls
,
name
)
:
namespace
[
name
]
=
make_method
(
name
)
return
type
(
"
%
s(
%
s)"
%
(
cls
.
__name__
,
theclass
.
__name__
),
(
cls
,),
namespace
)
...
...
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