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
559c04f3
Commit
559c04f3
authored
Aug 01, 2014
by
Victor Lin
Committed by
James Cammarata
Aug 27, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement omit for module args, also add tests for it
parent
bce6642a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
21 deletions
+46
-21
lib/ansible/runner/__init__.py
+13
-12
lib/ansible/runner/filter_plugins/core.py
+0
-9
lib/ansible/utils/__init__.py
+4
-0
test/integration/roles/test_good_parsing/tasks/main.yml
+29
-0
No files found.
lib/ansible/runner/__init__.py
View file @
559c04f3
...
...
@@ -624,6 +624,7 @@ class Runner(object):
inject
[
'defaults'
]
=
self
.
default_vars
inject
[
'environment'
]
=
self
.
environment
inject
[
'playbook_dir'
]
=
os
.
path
.
abspath
(
self
.
basedir
)
inject
[
'omit'
]
=
OMIT_PLACE_HOLDER
# template this one is available, callbacks use this
delegate_to
=
self
.
module_vars
.
get
(
'delegate_to'
)
...
...
@@ -867,11 +868,8 @@ class Runner(object):
# allow module args to work as a dictionary
# though it is usually a string
if
type
(
module_args
)
==
dict
:
new_args
=
[]
for
(
k
,
v
)
in
module_args
.
iteritems
():
new_args
.
append
(
"
%
s='
%
s'"
%
(
k
,
v
))
module_args
=
' '
.
join
(
new_args
)
if
isinstance
(
module_args
,
dict
):
module_args
=
utils
.
serialize_args
(
module_args
)
# render module_args and complex_args templates
try
:
...
...
@@ -893,13 +891,16 @@ class Runner(object):
except
jinja2
.
exceptions
.
UndefinedError
,
e
:
raise
errors
.
AnsibleUndefinedVariable
(
"One or more undefined variables:
%
s"
%
str
(
e
))
# filter omitted arguments out
new_complex_args
=
{}
for
key
,
value
in
complex_args
.
iteritems
():
if
value
==
OMIT_PLACE_HOLDER
:
continue
new_complex_args
[
key
]
=
value
complex_args
=
new_complex_args
def
not_omitted
(
item
):
return
item
[
1
]
!=
OMIT_PLACE_HOLDER
if
module_name
not
in
[
'shell'
,
'command'
]:
# filter omitted arguments out from complex_args
complex_args
=
dict
(
filter
(
not_omitted
,
complex_args
.
iteritems
()))
# filter omitted arguments out from module_args
module_kv
=
utils
.
parse_kv
(
module_args
)
module_kv
=
dict
(
filter
(
not_omitted
,
module_kv
.
iteritems
()))
module_args
=
utils
.
serialize_args
(
module_kv
)
result
=
handler
.
run
(
conn
,
tmp
,
module_name
,
module_args
,
inject
,
complex_args
)
# Code for do until feature
...
...
lib/ansible/runner/filter_plugins/core.py
View file @
559c04f3
...
...
@@ -32,7 +32,6 @@ from ansible.utils import md5s, OMIT_PLACE_HOLDER
from
distutils.version
import
LooseVersion
,
StrictVersion
from
random
import
SystemRandom
from
jinja2.filters
import
environmentfilter
from
jinja2.runtime
import
Undefined
def
to_nice_yaml
(
*
a
,
**
kw
):
...
...
@@ -239,12 +238,6 @@ def rand(environment, end, start=None, step=None):
raise
errors
.
AnsibleFilterError
(
'random can only be used on sequences and integers'
)
def
default_omit
(
a
):
if
isinstance
(
a
,
Undefined
):
return
OMIT_PLACE_HOLDER
return
a
class
FilterModule
(
object
):
''' Ansible core jinja2 filters '''
...
...
@@ -316,6 +309,4 @@ class FilterModule(object):
# random numbers
'random'
:
rand
,
'default_omit'
:
default_omit
,
}
lib/ansible/utils/__init__.py
View file @
559c04f3
...
...
@@ -787,6 +787,10 @@ def _validate_both_dicts(a, b):
"failed to combine variables, expected dicts but got a '
%
s' and a '
%
s'"
%
(
type
(
a
)
.
__name__
,
type
(
b
)
.
__name__
)
)
def
serialize_args
(
args
):
''' convert a dict to a string of key/value items '''
return
' '
.
join
(
"
%
s='
%
s'"
%
item
for
item
in
args
.
iteritems
())
def
merge_hash
(
a
,
b
):
''' recursively merges hash b into a
keys from b take precedence over keys from a '''
...
...
test/integration/roles/test_good_parsing/tasks/main.yml
View file @
559c04f3
...
...
@@ -172,3 +172,32 @@
assert
:
that
:
-
nested_include_var is undefined
-
name
:
test omit in complex args
set_fact
:
foo
:
bar
spam
:
"
{{
omit
}}"
should_not_omit
:
"
prefix{{
omit
}}"
-
assert
:
that
:
-
foo == 'bar'
-
spam is undefined
-
should_not_omit == "prefix{{ omit }}"
-
name
:
test omit in module args
set_fact
:
>
yo=whatsup
eggs="{{ omit }}"
default_omitted="{{ not_exists|default(omit) }}"
should_not_omit_1="prefix{{ omit }}"
should_not_omit_2="{{ omit }}suffix"
-
assert
:
that
:
-
yo == 'whatsup'
-
eggs is undefined
-
default_omitted is undefined
-
should_not_omit_1 == "prefix{{ omit }}"
-
should_not_omit_2 == "{{ omit }}suffix"
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