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
e8aa847e
Commit
e8aa847e
authored
Oct 06, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Attempt to clean up the munging functions a little.
parent
d97b38ba
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
27 deletions
+42
-27
v2/ansible/playbook/task.py
+42
-27
No files found.
v2/ansible/playbook/task.py
View file @
e8aa847e
...
...
@@ -103,6 +103,9 @@ class Task(Base):
else
:
return
"
%
s
%
s"
%
(
self
.
action
,
self
.
_merge_kv
(
self
.
args
))
def
_parse_kv
(
self
,
str
):
return
ansible
.
utils
.
parse_kv
(
str
)
def
_merge_kv
(
self
,
ds
):
if
ds
is
None
:
return
""
...
...
@@ -124,47 +127,59 @@ class Task(Base):
''' returns a human readable representation of the task '''
return
"TASK:
%
s"
%
self
.
get_name
()
def
munge
(
self
,
ds
):
'''
tasks are especially complex arguments so need pre-processing.
keep it short.
'''
assert
isinstance
(
ds
,
dict
)
new_ds
=
dict
()
for
(
k
,
v
)
in
ds
.
iteritems
():
# if any attributes of the datastructure match a module name
# convert it to "module + args"
if
k
in
module_finder
:
def
_munge_action
(
self
,
ds
,
new_ds
,
k
,
v
):
''' take a module name and split into action and args '''
if
self
.
_action
.
value
is
not
None
or
'action'
in
ds
or
'local_action'
in
ds
:
raise
AnsibleError
(
"duplicate action in task:
%
s"
%
k
)
print
"SCANNED:
%
s"
%
k
new_ds
[
'action'
]
=
k
new_ds
[
'args'
]
=
v
# handle any loops, there can be only one kind of loop
elif
"with_
%
s"
%
k
in
lookup_finder
:
def
_munge_loop
(
self
,
ds
,
new_ds
,
k
,
v
):
''' take a lookup plugin name and store it correctly '''
if
self
.
_loop
.
value
is
not
None
:
raise
AnsibleError
(
"duplicate loop in task:
%
s"
%
k
)
new_ds
[
'loop'
]
=
k
new_ds
[
'loop_args'
]
=
v
# otherwise send it through straight
def
_munge_action2
(
self
,
ds
,
new_ds
,
k
,
v
,
local
=
False
):
''' take an old school action/local_action and reformat it '''
if
isinstance
(
v
,
basestring
):
(
module
,
args
)
=
self
.
_parse_kv
(
v
)
new_ds
[
'action'
]
=
module
if
'args'
in
ds
:
raise
AnsibleError
(
"unexpected and redundant 'args'"
)
new_ds
[
'args'
]
=
args
if
local
:
if
'delegate_to'
in
ds
:
raise
AnsbileError
(
"local_action and action conflict"
)
new_ds
[
'delegate_to'
]
=
'localhost'
else
:
raise
AnsibleError
(
"unexpected use of 'action'"
)
else
:
raise
AnsibleError
(
"unexpected use of 'action'"
)
def
munge
(
self
,
ds
):
'''
tasks are especially complex arguments so need pre-processing.
keep it short.
'''
assert
isinstance
(
ds
,
dict
)
new_ds
=
dict
()
for
(
k
,
v
)
in
ds
.
iteritems
():
if
k
in
module_finder
:
self
.
_munge_action
(
ds
,
new_ds
,
k
,
v
)
elif
"with_
%
s"
%
k
in
lookup_finder
:
self
.
_munge_loop
(
new_ds
,
k
,
v
)
elif
k
==
'action'
:
self
.
_munge_action2
(
ds
,
new_ds
,
k
,
v
)
elif
k
==
'local_action'
:
self
.
_munge_action2
(
ds
,
new_ds
,
k
,
v
,
local
=
True
)
else
:
# nothing we need to filter
print
"PASSING:
%
s =>
%
s"
%
(
k
,
v
)
new_ds
[
k
]
=
v
print
"NEW_DS=
%
s"
%
new_ds
return
new_ds
...
...
@@ -184,7 +199,7 @@ LEGACY = """
if module_name not in module_finder:
raise AnsibleError("the specified module '
%
s' could not be found, check your module path"
%
module_name)
results['_module_name'] = module_name
results['_parameters'] =
utils.
parse_kv(params)
results['_parameters'] =
self._
parse_kv(params)
if k == 'local_action':
if 'delegate_to' in ds:
...
...
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