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
0b4d7f15
Commit
0b4d7f15
authored
Jul 28, 2014
by
Victor Lin
Committed by
James Cammarata
Aug 27, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement default omit filter
parent
b6a30a73
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
10 deletions
+34
-10
lib/ansible/runner/__init__.py
+13
-8
lib/ansible/runner/filter_plugins/core.py
+15
-2
lib/ansible/utils/__init__.py
+6
-0
No files found.
lib/ansible/runner/__init__.py
View file @
0b4d7f15
...
@@ -49,6 +49,7 @@ from ansible.module_common import ModuleReplacer
...
@@ -49,6 +49,7 @@ from ansible.module_common import ModuleReplacer
from
ansible.module_utils.splitter
import
split_args
from
ansible.module_utils.splitter
import
split_args
from
ansible.cache
import
FactCache
from
ansible.cache
import
FactCache
from
ansible.utils
import
update_hash
from
ansible.utils
import
update_hash
from
ansible.utils
import
OMIT_PLACE_HOLDER
module_replacer
=
ModuleReplacer
(
strip_comments
=
False
)
module_replacer
=
ModuleReplacer
(
strip_comments
=
False
)
...
@@ -740,14 +741,6 @@ class Runner(object):
...
@@ -740,14 +741,6 @@ class Runner(object):
if
self
.
su_user_var
is
not
None
:
if
self
.
su_user_var
is
not
None
:
self
.
su_user
=
template
.
template
(
self
.
basedir
,
self
.
su_user_var
,
inject
)
self
.
su_user
=
template
.
template
(
self
.
basedir
,
self
.
su_user_var
,
inject
)
# allow module args to work as a dictionary
# though it is usually a string
new_args
=
""
if
type
(
module_args
)
==
dict
:
for
(
k
,
v
)
in
module_args
.
iteritems
():
new_args
=
new_args
+
"
%
s='
%
s' "
%
(
k
,
v
)
module_args
=
new_args
# module_name may be dynamic (but cannot contain {{ ansible_ssh_user }})
# module_name may be dynamic (but cannot contain {{ ansible_ssh_user }})
module_name
=
template
.
template
(
self
.
basedir
,
module_name
,
inject
)
module_name
=
template
.
template
(
self
.
basedir
,
module_name
,
inject
)
...
@@ -872,6 +865,18 @@ class Runner(object):
...
@@ -872,6 +865,18 @@ class Runner(object):
if
self
.
_early_needs_tmp_path
(
module_name
,
handler
):
if
self
.
_early_needs_tmp_path
(
module_name
,
handler
):
tmp
=
self
.
_make_tmp_path
(
conn
)
tmp
=
self
.
_make_tmp_path
(
conn
)
# 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
():
# see if the value is OMIT_PLACE_HOLDER, if it is, skip it
arg_value
=
template
.
template
(
self
.
basedir
,
v
,
inject
,
fail_on_undefined
=
self
.
error_on_undefined_vars
)
if
arg_value
.
strip
()
==
OMIT_PLACE_HOLDER
:
continue
new_args
.
append
(
"
%
s='
%
s'"
%
(
k
,
v
))
module_args
=
' '
.
join
(
new_args
)
# render module_args and complex_args templates
# render module_args and complex_args templates
try
:
try
:
# When templating module_args, we need to be careful to ensure
# When templating module_args, we need to be careful to ensure
...
...
lib/ansible/runner/filter_plugins/core.py
View file @
0b4d7f15
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import
os
import
base64
import
base64
import
json
import
json
import
os.path
import
os.path
...
@@ -25,12 +26,14 @@ import glob
...
@@ -25,12 +26,14 @@ import glob
import
re
import
re
import
collections
import
collections
import
operator
as
py_operator
import
operator
as
py_operator
import
hashlib
from
ansible
import
errors
from
ansible
import
errors
from
ansible.utils
import
md5s
from
ansible.utils
import
md5s
,
OMIT_PLACE_HOLDER
from
distutils.version
import
LooseVersion
,
StrictVersion
from
distutils.version
import
LooseVersion
,
StrictVersion
from
random
import
SystemRandom
from
random
import
SystemRandom
from
jinja2.filters
import
environmentfilter
from
jinja2.filters
import
environmentfilter
def
to_nice_yaml
(
*
a
,
**
kw
):
def
to_nice_yaml
(
*
a
,
**
kw
):
'''Make verbose, human readable yaml'''
'''Make verbose, human readable yaml'''
return
yaml
.
safe_dump
(
*
a
,
indent
=
4
,
allow_unicode
=
True
,
default_flow_style
=
False
,
**
kw
)
return
yaml
.
safe_dump
(
*
a
,
indent
=
4
,
allow_unicode
=
True
,
default_flow_style
=
False
,
**
kw
)
...
@@ -234,6 +237,15 @@ def rand(environment, end, start=None, step=None):
...
@@ -234,6 +237,15 @@ def rand(environment, end, start=None, step=None):
else
:
else
:
raise
errors
.
AnsibleFilterError
(
'random can only be used on sequences and integers'
)
raise
errors
.
AnsibleFilterError
(
'random can only be used on sequences and integers'
)
def
default_omit
(
a
):
try
:
a
except
NameError
:
return
OMIT_PLACE_HOLDER
else
:
return
a
class
FilterModule
(
object
):
class
FilterModule
(
object
):
''' Ansible core jinja2 filters '''
''' Ansible core jinja2 filters '''
...
@@ -305,5 +317,6 @@ class FilterModule(object):
...
@@ -305,5 +317,6 @@ class FilterModule(object):
# random numbers
# random numbers
'random'
:
rand
,
'random'
:
rand
,
}
'default_omit'
:
default_omit
,
}
lib/ansible/utils/__init__.py
View file @
0b4d7f15
...
@@ -61,6 +61,7 @@ LOOKUP_REGEX = re.compile(r'lookup\s*\(')
...
@@ -61,6 +61,7 @@ LOOKUP_REGEX = re.compile(r'lookup\s*\(')
PRINT_CODE_REGEX
=
re
.
compile
(
r'(?:{[{
%
]|[
%
}]})'
)
PRINT_CODE_REGEX
=
re
.
compile
(
r'(?:{[{
%
]|[
%
}]})'
)
CODE_REGEX
=
re
.
compile
(
r'(?:{
%
|
%
})'
)
CODE_REGEX
=
re
.
compile
(
r'(?:{
%
|
%
})'
)
try
:
try
:
import
json
import
json
except
ImportError
:
except
ImportError
:
...
@@ -110,6 +111,11 @@ try:
...
@@ -110,6 +111,11 @@ try:
except
ImportError
:
except
ImportError
:
pass
pass
OMIT_PLACE_HOLDER
=
(
'__omit_place_holder__
%
s'
%
_md5
(
os
.
urandom
(
64
))
.
hexdigest
()
)
###############################################################
###############################################################
# Abstractions around keyczar
# Abstractions around keyczar
###############################################################
###############################################################
...
...
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