Additional fixes for the new omit parameter variable

pull/7703/head
James Cammarata 10 years ago
parent 6260635c65
commit e99db078b4

@ -53,6 +53,11 @@ from ansible.utils import OMIT_PLACE_HOLDER
module_replacer = ModuleReplacer(strip_comments=False) module_replacer = ModuleReplacer(strip_comments=False)
try:
from hashlib import md5 as _md5
except ImportError:
from md5 import md5 as _md5
HAS_ATFORK=True HAS_ATFORK=True
try: try:
from Crypto.Random import atfork from Crypto.Random import atfork
@ -203,6 +208,7 @@ class Runner(object):
self.su_user_var = su_user self.su_user_var = su_user
self.su_user = None self.su_user = None
self.su_pass = su_pass self.su_pass = su_pass
self.omit_token = '__omit_place_holder__%s' % _md5(os.urandom(64)).hexdigest()
self.vault_pass = vault_pass self.vault_pass = vault_pass
self.no_log = no_log self.no_log = no_log
self.run_once = run_once self.run_once = run_once
@ -623,8 +629,13 @@ class Runner(object):
inject['vars'] = self.module_vars inject['vars'] = self.module_vars
inject['defaults'] = self.default_vars inject['defaults'] = self.default_vars
inject['environment'] = self.environment inject['environment'] = self.environment
<<<<<<< HEAD
inject['playbook_dir'] = os.path.abspath(self.basedir) inject['playbook_dir'] = os.path.abspath(self.basedir)
inject['omit'] = OMIT_PLACE_HOLDER inject['omit'] = OMIT_PLACE_HOLDER
=======
inject['playbook_dir'] = self.basedir
inject['omit'] = self.omit_token
>>>>>>> Additional fixes for the new omit parameter variable
# template this one is available, callbacks use this # template this one is available, callbacks use this
delegate_to = self.module_vars.get('delegate_to') delegate_to = self.module_vars.get('delegate_to')
@ -892,9 +903,9 @@ class Runner(object):
raise errors.AnsibleUndefinedVariable("One or more undefined variables: %s" % str(e)) raise errors.AnsibleUndefinedVariable("One or more undefined variables: %s" % str(e))
def not_omitted(item): def not_omitted(item):
return item[1] != OMIT_PLACE_HOLDER return item[1] != self.omit_token
if module_name not in ['shell', 'command']: if module_name not in ['shell', 'command', 'include_vars']:
# filter omitted arguments out from complex_args # filter omitted arguments out from complex_args
complex_args = dict(filter(not_omitted, complex_args.iteritems())) complex_args = dict(filter(not_omitted, complex_args.iteritems()))
# filter omitted arguments out from module_args # filter omitted arguments out from module_args

@ -112,10 +112,6 @@ except ImportError:
pass pass
OMIT_PLACE_HOLDER = (
'__omit_place_holder__%s' % _md5(os.urandom(64)).hexdigest()
)
############################################################### ###############################################################
# Abstractions around keyczar # Abstractions around keyczar
############################################################### ###############################################################
@ -787,10 +783,6 @@ 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__) "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): def merge_hash(a, b):
''' recursively merges hash b into a ''' recursively merges hash b into a
keys from b take precedence over keys from a ''' keys from b take precedence over keys from a '''

@ -183,7 +183,7 @@
that: that:
- foo == 'bar' - foo == 'bar'
- spam is undefined - spam is undefined
- should_not_omit == "prefix{{ omit }}" - should_not_omit is defined
- name: test omit in module args - name: test omit in module args
set_fact: > set_fact: >
@ -199,6 +199,6 @@
- yo == 'whatsup' - yo == 'whatsup'
- eggs is undefined - eggs is undefined
- default_omitted is undefined - default_omitted is undefined
- should_not_omit_1 == "prefix{{ omit }}" - should_not_omit_1 is defined
- should_not_omit_2 == "{{ omit }}suffix" - should_not_omit_2 is defined
- should_not_omit_3 == "__omit_place_holder__afb6b9bc3d20bfeaa00a1b23a5930f89" - should_not_omit_3 == "__omit_place_holder__afb6b9bc3d20bfeaa00a1b23a5930f89"

Loading…
Cancel
Save