Fixing more v2 bugs

This commit is contained in:
James Cammarata 2015-01-29 16:43:50 -06:00
parent d57f7b4b9e
commit c978c77796
5 changed files with 23 additions and 17 deletions

@ -1 +1 @@
Subproject commit 256ce9dd4dfbe2b0dc9eb5031812c8ab76418a22 Subproject commit e355f7bf12465ed3f25a2147d6940179db2a26aa

View file

@ -53,7 +53,7 @@ class Conditional:
False if any of them evaluate as such. False if any of them evaluate as such.
''' '''
templar = Templar(loader=self._loader, variables=all_vars) templar = Templar(loader=self._loader, variables=all_vars, fail_on_undefined=False)
for conditional in self.when: for conditional in self.when:
if not self._check_conditional(conditional, templar, all_vars): if not self._check_conditional(conditional, templar, all_vars):
return False return False
@ -69,20 +69,15 @@ class Conditional:
if conditional is None or conditional == '': if conditional is None or conditional == '':
return True return True
# FIXME: is this required? there is no indication what it does # FIXME: this should be removable now, leaving it here just in case
#conditional = conditional.replace("jinja2_compare ","")
# allow variable names # allow variable names
#if conditional in all_vars and '-' not in str(all_vars[conditional]): #if conditional in all_vars and '-' not in str(all_vars[conditional]):
# conditional = all_vars[conditional] # conditional = all_vars[conditional]
conditional = templar.template(conditional, convert_bare=True) conditional = templar.template(conditional, convert_bare=True)
if not isinstance(conditional, basestring): if not isinstance(conditional, basestring) or conditional == "":
return conditional return conditional
# FIXME: same as above
#original = str(conditional).replace("jinja2_compare ","")
# a Jinja2 evaluation that results in something Python can eval! # a Jinja2 evaluation that results in something Python can eval!
presented = "{%% if %s %%} True {%% else %%} False {%% endif %%}" % conditional presented = "{%% if %s %%} True {%% else %%} False {%% endif %%}" % conditional
conditional = templar.template(presented) conditional = templar.template(presented)

View file

@ -46,13 +46,21 @@ __all__ = ['Role', 'ROLE_CACHE', 'hash_params']
# in a static method. This is also used in the base class for # in a static method. This is also used in the base class for
# strategies (ansible/plugins/strategies/__init__.py) # strategies (ansible/plugins/strategies/__init__.py)
def hash_params(params): def hash_params(params):
s = set() if not isinstance(params, dict):
for k,v in params.iteritems(): return params
if isinstance(v, dict): else:
s.update((k, hash_params(v))) s = set()
else: for k,v in params.iteritems():
s.update((k, v)) if isinstance(v, dict):
return frozenset(s) s.update((k, hash_params(v)))
elif isinstance(v, list):
things = []
for item in v:
things.append(hash_params(item))
s.update((k, tuple(things)))
else:
s.update((k, v))
return frozenset(s)
# The role cache is used to prevent re-loading roles, which # The role cache is used to prevent re-loading roles, which
# may already exist. Keys into this cache are the SHA1 hash # may already exist. Keys into this cache are the SHA1 hash

View file

@ -279,7 +279,7 @@ class Connection(ConnectionBase):
# ssh_cmd += ['-6'] # ssh_cmd += ['-6']
ssh_cmd += [self._host.ipv4_address] ssh_cmd += [self._host.ipv4_address]
if not (self._connection_info.sudo or self._connection_info.su) or not sudoable: if not (self._connection_info.sudo or self._connection_info.su):
prompt = None prompt = None
if executable: if executable:
ssh_cmd.append(executable + ' -c ' + pipes.quote(cmd)) ssh_cmd.append(executable + ' -c ' + pipes.quote(cmd))

View file

@ -210,6 +210,9 @@ class VariableManager:
hostvars = HostVars(vars_manager=self, inventory=self._inventory, loader=loader) hostvars = HostVars(vars_manager=self, inventory=self._inventory, loader=loader)
all_vars['hostvars'] = hostvars all_vars['hostvars'] = hostvars
if self._inventory is not None:
all_vars['inventory_dir'] = self._inventory.basedir()
# the 'omit' value alows params to be left out if the variable they are based on is undefined # the 'omit' value alows params to be left out if the variable they are based on is undefined
all_vars['omit'] = self._omit_token all_vars['omit'] = self._omit_token