mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Use 'except ... as' syntax
This syntax works on Python 2.6 through 3.x. lib/ansible/module_utils (and lib/ansible/modules) need to support Python 2.4, so I didn't touch those.
This commit is contained in:
parent
2ac931d6c9
commit
0c6ce31f76
24 changed files with 51 additions and 51 deletions
|
@ -120,7 +120,7 @@ class DocCLI(CLI):
|
||||||
# this typically means we couldn't even parse the docstring, not just that the YAML is busted,
|
# this typically means we couldn't even parse the docstring, not just that the YAML is busted,
|
||||||
# probably a quoting issue.
|
# probably a quoting issue.
|
||||||
raise AnsibleError("Parsing produced an empty object.")
|
raise AnsibleError("Parsing produced an empty object.")
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.display.vvv(traceback.print_exc())
|
self.display.vvv(traceback.print_exc())
|
||||||
raise AnsibleError("module %s missing documentation (or could not parse documentation): %s\n" % (module, str(e)))
|
raise AnsibleError("module %s missing documentation (or could not parse documentation): %s\n" % (module, str(e)))
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,7 @@ class PullCLI(CLI):
|
||||||
os.chdir('/')
|
os.chdir('/')
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(self.options.dest)
|
shutil.rmtree(self.options.dest)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.display.error("Failed to remove %s: %s" % (self.options.dest, str(e)))
|
self.display.error("Failed to remove %s: %s" % (self.options.dest, str(e)))
|
||||||
|
|
||||||
return rc
|
return rc
|
||||||
|
|
|
@ -67,7 +67,7 @@ class WorkerProcess(multiprocessing.Process):
|
||||||
if fileno is not None:
|
if fileno is not None:
|
||||||
try:
|
try:
|
||||||
self._new_stdin = os.fdopen(os.dup(fileno))
|
self._new_stdin = os.fdopen(os.dup(fileno))
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
# couldn't dupe stdin, most likely because it's
|
# couldn't dupe stdin, most likely because it's
|
||||||
# not a valid file descriptor, so we just rely on
|
# not a valid file descriptor, so we just rely on
|
||||||
# using the one that was passed in
|
# using the one that was passed in
|
||||||
|
@ -137,7 +137,7 @@ class WorkerProcess(multiprocessing.Process):
|
||||||
except:
|
except:
|
||||||
# FIXME: most likely an abort, catch those kinds of errors specifically
|
# FIXME: most likely an abort, catch those kinds of errors specifically
|
||||||
break
|
break
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
debug("WORKER EXCEPTION: %s" % e)
|
debug("WORKER EXCEPTION: %s" % e)
|
||||||
debug("WORKER EXCEPTION: %s" % traceback.format_exc())
|
debug("WORKER EXCEPTION: %s" % traceback.format_exc())
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -125,14 +125,14 @@ class TaskExecutor:
|
||||||
result = json.dumps(res)
|
result = json.dumps(res)
|
||||||
debug("done dumping result, returning")
|
debug("done dumping result, returning")
|
||||||
return result
|
return result
|
||||||
except AnsibleError, e:
|
except AnsibleError as e:
|
||||||
return dict(failed=True, msg=to_unicode(e, nonstring='simplerepr'))
|
return dict(failed=True, msg=to_unicode(e, nonstring='simplerepr'))
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
self._connection.close()
|
self._connection.close()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
debug("error closing connection: %s" % to_unicode(e))
|
debug("error closing connection: %s" % to_unicode(e))
|
||||||
|
|
||||||
def _get_loop_items(self):
|
def _get_loop_items(self):
|
||||||
|
@ -187,7 +187,7 @@ class TaskExecutor:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tmp_task = self._task.copy()
|
tmp_task = self._task.copy()
|
||||||
except AnsibleParserError, e:
|
except AnsibleParserError as e:
|
||||||
results.append(dict(failed=True, msg=str(e)))
|
results.append(dict(failed=True, msg=str(e)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ class Inventory(object):
|
||||||
return re.search(pattern_str[1:], str)
|
return re.search(pattern_str[1:], str)
|
||||||
else:
|
else:
|
||||||
return fnmatch.fnmatch(str, pattern_str)
|
return fnmatch.fnmatch(str, pattern_str)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise AnsibleError('invalid host pattern: %s' % pattern_str)
|
raise AnsibleError('invalid host pattern: %s' % pattern_str)
|
||||||
|
|
||||||
def _match_list(self, items, item_attr, pattern_str):
|
def _match_list(self, items, item_attr, pattern_str):
|
||||||
|
@ -153,7 +153,7 @@ class Inventory(object):
|
||||||
pattern = re.compile(fnmatch.translate(pattern_str))
|
pattern = re.compile(fnmatch.translate(pattern_str))
|
||||||
else:
|
else:
|
||||||
pattern = re.compile(pattern_str[1:])
|
pattern = re.compile(pattern_str[1:])
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise AnsibleError('invalid host pattern: %s' % pattern_str)
|
raise AnsibleError('invalid host pattern: %s' % pattern_str)
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
|
|
|
@ -46,7 +46,7 @@ class InventoryScript:
|
||||||
cmd = [ self.filename, "--list" ]
|
cmd = [ self.filename, "--list" ]
|
||||||
try:
|
try:
|
||||||
sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
raise AnsibleError("problem running %s (%s)" % (' '.join(cmd), e))
|
raise AnsibleError("problem running %s (%s)" % (' '.join(cmd), e))
|
||||||
(stdout, stderr) = sp.communicate()
|
(stdout, stderr) = sp.communicate()
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ class InventoryScript:
|
||||||
cmd = [self.filename, "--host", host.name]
|
cmd = [self.filename, "--host", host.name]
|
||||||
try:
|
try:
|
||||||
sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
raise AnsibleError("problem running %s (%s)" % (' '.join(cmd), e))
|
raise AnsibleError("problem running %s (%s)" % (' '.join(cmd), e))
|
||||||
(out, err) = sp.communicate()
|
(out, err) = sp.communicate()
|
||||||
if out.strip() == '':
|
if out.strip() == '':
|
||||||
|
|
|
@ -66,7 +66,7 @@ class Conditional:
|
||||||
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
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise AnsibleError("The conditional check '%s' failed. The error was: %s" % (conditional, e), obj=ds)
|
raise AnsibleError("The conditional check '%s' failed. The error was: %s" % (conditional, e), obj=ds)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
12
lib/ansible/plugins/cache/jsonfile.py
vendored
12
lib/ansible/plugins/cache/jsonfile.py
vendored
|
@ -45,7 +45,7 @@ class CacheModule(BaseCacheModule):
|
||||||
if not os.path.exists(self._cache_dir):
|
if not os.path.exists(self._cache_dir):
|
||||||
try:
|
try:
|
||||||
os.makedirs(self._cache_dir)
|
os.makedirs(self._cache_dir)
|
||||||
except (OSError,IOError), e:
|
except (OSError,IOError) as e:
|
||||||
self._display.warning("error while trying to create cache dir %s : %s" % (self._cache_dir, str(e)))
|
self._display.warning("error while trying to create cache dir %s : %s" % (self._cache_dir, str(e)))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class CacheModule(BaseCacheModule):
|
||||||
cachefile = "%s/%s" % (self._cache_dir, key)
|
cachefile = "%s/%s" % (self._cache_dir, key)
|
||||||
try:
|
try:
|
||||||
f = codecs.open(cachefile, 'r', encoding='utf-8')
|
f = codecs.open(cachefile, 'r', encoding='utf-8')
|
||||||
except (OSError,IOError), e:
|
except (OSError,IOError) as e:
|
||||||
self._display.warning("error while trying to read %s : %s" % (cachefile, str(e)))
|
self._display.warning("error while trying to read %s : %s" % (cachefile, str(e)))
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -81,7 +81,7 @@ class CacheModule(BaseCacheModule):
|
||||||
cachefile = "%s/%s" % (self._cache_dir, key)
|
cachefile = "%s/%s" % (self._cache_dir, key)
|
||||||
try:
|
try:
|
||||||
f = codecs.open(cachefile, 'w', encoding='utf-8')
|
f = codecs.open(cachefile, 'w', encoding='utf-8')
|
||||||
except (OSError,IOError), e:
|
except (OSError,IOError) as e:
|
||||||
self._display.warning("error while trying to write to %s : %s" % (cachefile, str(e)))
|
self._display.warning("error while trying to write to %s : %s" % (cachefile, str(e)))
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -94,7 +94,7 @@ class CacheModule(BaseCacheModule):
|
||||||
cachefile = "%s/%s" % (self._cache_dir, key)
|
cachefile = "%s/%s" % (self._cache_dir, key)
|
||||||
try:
|
try:
|
||||||
st = os.stat(cachefile)
|
st = os.stat(cachefile)
|
||||||
except (OSError,IOError), e:
|
except (OSError,IOError) as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
@ -126,7 +126,7 @@ class CacheModule(BaseCacheModule):
|
||||||
try:
|
try:
|
||||||
st = os.stat(cachefile)
|
st = os.stat(cachefile)
|
||||||
return True
|
return True
|
||||||
except (OSError,IOError), e:
|
except (OSError,IOError) as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
@ -137,7 +137,7 @@ class CacheModule(BaseCacheModule):
|
||||||
del self._cache[key]
|
del self._cache[key]
|
||||||
try:
|
try:
|
||||||
os.remove("%s/%s" % (self._cache_dir, key))
|
os.remove("%s/%s" % (self._cache_dir, key))
|
||||||
except (OSError,IOError), e:
|
except (OSError,IOError) as e:
|
||||||
pass #TODO: only pass on non existing?
|
pass #TODO: only pass on non existing?
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
|
|
|
@ -152,7 +152,7 @@ def version_compare(value, version, operator='eq', strict=False):
|
||||||
try:
|
try:
|
||||||
method = getattr(py_operator, operator)
|
method = getattr(py_operator, operator)
|
||||||
return method(Version(str(value)), Version(str(version)))
|
return method(Version(str(value)), Version(str(version)))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise errors.AnsibleFilterError('Version comparison: %s' % e)
|
raise errors.AnsibleFilterError('Version comparison: %s' % e)
|
||||||
|
|
||||||
def regex_escape(string):
|
def regex_escape(string):
|
||||||
|
|
|
@ -80,14 +80,14 @@ def logarithm(x, base=math.e):
|
||||||
return math.log10(x)
|
return math.log10(x)
|
||||||
else:
|
else:
|
||||||
return math.log(x, base)
|
return math.log(x, base)
|
||||||
except TypeError, e:
|
except TypeError as e:
|
||||||
raise errors.AnsibleFilterError('log() can only be used on numbers: %s' % str(e))
|
raise errors.AnsibleFilterError('log() can only be used on numbers: %s' % str(e))
|
||||||
|
|
||||||
|
|
||||||
def power(x, y):
|
def power(x, y):
|
||||||
try:
|
try:
|
||||||
return math.pow(x, y)
|
return math.pow(x, y)
|
||||||
except TypeError, e:
|
except TypeError as e:
|
||||||
raise errors.AnsibleFilterError('pow() can only be used on numbers: %s' % str(e))
|
raise errors.AnsibleFilterError('pow() can only be used on numbers: %s' % str(e))
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ def inversepower(x, base=2):
|
||||||
return math.sqrt(x)
|
return math.sqrt(x)
|
||||||
else:
|
else:
|
||||||
return math.pow(x, 1.0/float(base))
|
return math.pow(x, 1.0/float(base))
|
||||||
except TypeError, e:
|
except TypeError as e:
|
||||||
raise errors.AnsibleFilterError('root() can only be used on numbers: %s' % str(e))
|
raise errors.AnsibleFilterError('root() can only be used on numbers: %s' % str(e))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ except ImportError:
|
||||||
try:
|
try:
|
||||||
import consul
|
import consul
|
||||||
HAS_CONSUL = True
|
HAS_CONSUL = True
|
||||||
except ImportError, e:
|
except ImportError as e:
|
||||||
HAS_CONSUL = False
|
HAS_CONSUL = False
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class LookupModule(LookupBase):
|
||||||
values.append(r['Value'])
|
values.append(r['Value'])
|
||||||
else:
|
else:
|
||||||
values.append(results[1]['Value'])
|
values.append(results[1]['Value'])
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise AnsibleError(
|
raise AnsibleError(
|
||||||
"Error locating '%s' in kv store. Error was %s" % (term, e))
|
"Error locating '%s' in kv store. Error was %s" % (term, e))
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ class LookupModule(LookupBase):
|
||||||
name, value = param.split('=')
|
name, value = param.split('=')
|
||||||
assert name in paramvals, "% not a valid consul lookup parameter" % name
|
assert name in paramvals, "% not a valid consul lookup parameter" % name
|
||||||
paramvals[name] = value
|
paramvals[name] = value
|
||||||
except (ValueError, AssertionError), e:
|
except (ValueError, AssertionError) as e:
|
||||||
raise AnsibleError(e)
|
raise AnsibleError(e)
|
||||||
|
|
||||||
return paramvals
|
return paramvals
|
||||||
|
|
|
@ -41,7 +41,7 @@ class LookupModule(LookupBase):
|
||||||
val = credstash.getSecret(term, **kwargs)
|
val = credstash.getSecret(term, **kwargs)
|
||||||
except credstash.ItemNotFound:
|
except credstash.ItemNotFound:
|
||||||
raise AnsibleError('Key {0} not found'.format(term))
|
raise AnsibleError('Key {0} not found'.format(term))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise AnsibleError('Encountered exception while fetching {0}: {1}'.format(term, e.message))
|
raise AnsibleError('Encountered exception while fetching {0}: {1}'.format(term, e.message))
|
||||||
ret.append(val)
|
ret.append(val)
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,7 @@ class LookupModule(LookupBase):
|
||||||
try:
|
try:
|
||||||
nsaddr = dns.resolver.query(ns)[0].address
|
nsaddr = dns.resolver.query(ns)[0].address
|
||||||
nameservers.append(nsaddr)
|
nameservers.append(nsaddr)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise AnsibleError("dns lookup NS: ", str(e))
|
raise AnsibleError("dns lookup NS: ", str(e))
|
||||||
myres.nameservers = nameservers
|
myres.nameservers = nameservers
|
||||||
continue
|
continue
|
||||||
|
@ -176,7 +176,7 @@ class LookupModule(LookupBase):
|
||||||
domain = n.to_text()
|
domain = n.to_text()
|
||||||
except dns.exception.SyntaxError:
|
except dns.exception.SyntaxError:
|
||||||
pass
|
pass
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise AnsibleError("dns.reversename unhandled exception", str(e))
|
raise AnsibleError("dns.reversename unhandled exception", str(e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -196,7 +196,7 @@ class LookupModule(LookupBase):
|
||||||
rd['ttl'] = answers.rrset.ttl
|
rd['ttl'] = answers.rrset.ttl
|
||||||
|
|
||||||
ret.append(rd)
|
ret.append(rd)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
ret.append(str(e))
|
ret.append(str(e))
|
||||||
|
|
||||||
except dns.resolver.NXDOMAIN:
|
except dns.resolver.NXDOMAIN:
|
||||||
|
@ -205,7 +205,7 @@ class LookupModule(LookupBase):
|
||||||
ret.append("")
|
ret.append("")
|
||||||
except dns.resolver.Timeout:
|
except dns.resolver.Timeout:
|
||||||
ret.append('')
|
ret.append('')
|
||||||
except dns.exception.DNSException, e:
|
except dns.exception.DNSException as e:
|
||||||
raise AnsibleError("dns.resolver unhandled exception", e)
|
raise AnsibleError("dns.resolver unhandled exception", e)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
|
@ -47,7 +47,7 @@ class LookupModule(LookupBase):
|
||||||
# Retrieve a single value
|
# Retrieve a single value
|
||||||
try:
|
try:
|
||||||
value = self.cp.get(section, key)
|
value = self.cp.get(section, key)
|
||||||
except ConfigParser.NoOptionError, e:
|
except ConfigParser.NoOptionError as e:
|
||||||
return dflt
|
return dflt
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class LookupModule(LookupBase):
|
||||||
name, value = param.split('=')
|
name, value = param.split('=')
|
||||||
assert(name in paramvals)
|
assert(name in paramvals)
|
||||||
paramvals[name] = value
|
paramvals[name] = value
|
||||||
except (ValueError, AssertionError), e:
|
except (ValueError, AssertionError) as e:
|
||||||
raise errors.AnsibleError(e)
|
raise errors.AnsibleError(e)
|
||||||
|
|
||||||
path = self._loader.path_dwim_relative(basedir, 'files', paramvals['file'])
|
path = self._loader.path_dwim_relative(basedir, 'files', paramvals['file'])
|
||||||
|
|
|
@ -32,7 +32,7 @@ class LookupModule(LookupBase):
|
||||||
for x in terms:
|
for x in terms:
|
||||||
try:
|
try:
|
||||||
intermediate = listify_lookup_plugin_terms(x, templar=self._templar, loader=self._loader, fail_on_undefined=True)
|
intermediate = listify_lookup_plugin_terms(x, templar=self._templar, loader=self._loader, fail_on_undefined=True)
|
||||||
except UndefinedError, e:
|
except UndefinedError as e:
|
||||||
raise AnsibleUndefinedVariable("One of the nested variables was undefined. The error was: %s" % e)
|
raise AnsibleUndefinedVariable("One of the nested variables was undefined. The error was: %s" % e)
|
||||||
results.append(intermediate)
|
results.append(intermediate)
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -186,7 +186,7 @@ class LookupModule(LookupBase):
|
||||||
try:
|
try:
|
||||||
if not self.parse_simple_args(term):
|
if not self.parse_simple_args(term):
|
||||||
self.parse_kv_args(parse_kv(term))
|
self.parse_kv_args(parse_kv(term))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise AnsibleError("unknown error parsing with_sequence arguments: %r. Error was: %s" % (term, e))
|
raise AnsibleError("unknown error parsing with_sequence arguments: %r. Error was: %s" % (term, e))
|
||||||
|
|
||||||
self.sanity_check()
|
self.sanity_check()
|
||||||
|
|
|
@ -55,7 +55,7 @@ class LookupModule(LookupBase):
|
||||||
assert(name in paramvals)
|
assert(name in paramvals)
|
||||||
paramvals[name] = value
|
paramvals[name] = value
|
||||||
|
|
||||||
except (ValueError, AssertionError), e:
|
except (ValueError, AssertionError) as e:
|
||||||
# In case "file" or "key" are not present
|
# In case "file" or "key" are not present
|
||||||
raise AnsibleError(e)
|
raise AnsibleError(e)
|
||||||
|
|
||||||
|
|
|
@ -382,7 +382,7 @@ class StrategyBase:
|
||||||
data = self._loader.load_from_file(included_file._filename)
|
data = self._loader.load_from_file(included_file._filename)
|
||||||
if data is None:
|
if data is None:
|
||||||
return []
|
return []
|
||||||
except AnsibleError, e:
|
except AnsibleError as e:
|
||||||
for host in included_file._hosts:
|
for host in included_file._hosts:
|
||||||
tr = TaskResult(host=host, task=included_file._task, return_data=dict(failed=True, reason=str(e)))
|
tr = TaskResult(host=host, task=included_file._task, return_data=dict(failed=True, reason=str(e)))
|
||||||
iterator.mark_host_failed(host)
|
iterator.mark_host_failed(host)
|
||||||
|
@ -455,7 +455,7 @@ class StrategyBase:
|
||||||
loader=self._loader,
|
loader=self._loader,
|
||||||
variable_manager=self._variable_manager
|
variable_manager=self._variable_manager
|
||||||
)
|
)
|
||||||
except AnsibleError, e:
|
except AnsibleError as e:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if len(included_files) > 0:
|
if len(included_files) > 0:
|
||||||
|
@ -475,7 +475,7 @@ class StrategyBase:
|
||||||
# and add the new blocks to the list of handler blocks
|
# and add the new blocks to the list of handler blocks
|
||||||
handler_block.block.extend(block.block)
|
handler_block.block.extend(block.block)
|
||||||
#iterator._play.handlers.extend(new_blocks)
|
#iterator._play.handlers.extend(new_blocks)
|
||||||
except AnsibleError, e:
|
except AnsibleError as e:
|
||||||
for host in included_file._hosts:
|
for host in included_file._hosts:
|
||||||
iterator.mark_host_failed(host)
|
iterator.mark_host_failed(host)
|
||||||
self._tqm._failed_hosts[host.name] = True
|
self._tqm._failed_hosts[host.name] = True
|
||||||
|
|
|
@ -144,7 +144,7 @@ class StrategyModule(StrategyBase):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
included_files = IncludedFile.process_include_results(host_results, self._tqm, iterator=iterator, loader=self._loader, variable_manager=self._variable_manager)
|
included_files = IncludedFile.process_include_results(host_results, self._tqm, iterator=iterator, loader=self._loader, variable_manager=self._variable_manager)
|
||||||
except AnsibleError, e:
|
except AnsibleError as e:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if len(included_files) > 0:
|
if len(included_files) > 0:
|
||||||
|
@ -153,7 +153,7 @@ class StrategyModule(StrategyBase):
|
||||||
# list of noop tasks, to make sure that they continue running in lock-step
|
# list of noop tasks, to make sure that they continue running in lock-step
|
||||||
try:
|
try:
|
||||||
new_blocks = self._load_included_file(included_file, iterator=iterator)
|
new_blocks = self._load_included_file(included_file, iterator=iterator)
|
||||||
except AnsibleError, e:
|
except AnsibleError as e:
|
||||||
for host in included_file._hosts:
|
for host in included_file._hosts:
|
||||||
iterator.mark_host_failed(host)
|
iterator.mark_host_failed(host)
|
||||||
self._display.warning(str(e))
|
self._display.warning(str(e))
|
||||||
|
|
|
@ -258,7 +258,7 @@ class StrategyModule(StrategyBase):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
included_files = IncludedFile.process_include_results(host_results, self._tqm, iterator=iterator, loader=self._loader, variable_manager=self._variable_manager)
|
included_files = IncludedFile.process_include_results(host_results, self._tqm, iterator=iterator, loader=self._loader, variable_manager=self._variable_manager)
|
||||||
except AnsibleError, e:
|
except AnsibleError as e:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if len(included_files) > 0:
|
if len(included_files) > 0:
|
||||||
|
@ -273,7 +273,7 @@ class StrategyModule(StrategyBase):
|
||||||
# list of noop tasks, to make sure that they continue running in lock-step
|
# list of noop tasks, to make sure that they continue running in lock-step
|
||||||
try:
|
try:
|
||||||
new_blocks = self._load_included_file(included_file, iterator=iterator)
|
new_blocks = self._load_included_file(included_file, iterator=iterator)
|
||||||
except AnsibleError, e:
|
except AnsibleError as e:
|
||||||
for host in included_file._hosts:
|
for host in included_file._hosts:
|
||||||
iterator.mark_host_failed(host)
|
iterator.mark_host_failed(host)
|
||||||
self._display.warning(str(e))
|
self._display.warning(str(e))
|
||||||
|
@ -296,7 +296,7 @@ class StrategyModule(StrategyBase):
|
||||||
iterator.add_tasks(host, all_blocks[host])
|
iterator.add_tasks(host, all_blocks[host])
|
||||||
|
|
||||||
self._display.debug("results queue empty")
|
self._display.debug("results queue empty")
|
||||||
except (IOError, EOFError), e:
|
except (IOError, EOFError) as e:
|
||||||
self._display.debug("got IOError/EOFError in task loop: %s" % e)
|
self._display.debug("got IOError/EOFError in task loop: %s" % e)
|
||||||
# most likely an abort, return failed
|
# most likely an abort, return failed
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -261,7 +261,7 @@ class Templar:
|
||||||
ran = instance.run(loop_terms, variables=self._available_variables, **kwargs)
|
ran = instance.run(loop_terms, variables=self._available_variables, **kwargs)
|
||||||
except (AnsibleUndefinedVariable, UndefinedError) as e:
|
except (AnsibleUndefinedVariable, UndefinedError) as e:
|
||||||
raise AnsibleUndefinedVariable(e)
|
raise AnsibleUndefinedVariable(e)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if self._fail_on_lookup_errors:
|
if self._fail_on_lookup_errors:
|
||||||
raise
|
raise
|
||||||
ran = None
|
ran = None
|
||||||
|
@ -299,9 +299,9 @@ class Templar:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
t = myenv.from_string(data)
|
t = myenv.from_string(data)
|
||||||
except TemplateSyntaxError, e:
|
except TemplateSyntaxError as e:
|
||||||
raise AnsibleError("template error while templating string: %s" % str(e))
|
raise AnsibleError("template error while templating string: %s" % str(e))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if 'recursion' in str(e):
|
if 'recursion' in str(e):
|
||||||
raise AnsibleError("recursive loop detected in template string: %s" % data)
|
raise AnsibleError("recursive loop detected in template string: %s" % data)
|
||||||
else:
|
else:
|
||||||
|
@ -317,7 +317,7 @@ class Templar:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = j2_concat(rf)
|
res = j2_concat(rf)
|
||||||
except TypeError, te:
|
except TypeError as te:
|
||||||
if 'StrictUndefined' in str(te):
|
if 'StrictUndefined' in str(te):
|
||||||
raise AnsibleUndefinedVariable(
|
raise AnsibleUndefinedVariable(
|
||||||
"Unable to look up a name or access an attribute in template string. " + \
|
"Unable to look up a name or access an attribute in template string. " + \
|
||||||
|
@ -338,7 +338,7 @@ class Templar:
|
||||||
res += '\n' * (data_newlines - res_newlines)
|
res += '\n' * (data_newlines - res_newlines)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
except (UndefinedError, AnsibleUndefinedVariable), e:
|
except (UndefinedError, AnsibleUndefinedVariable) as e:
|
||||||
if fail_on_undefined:
|
if fail_on_undefined:
|
||||||
raise AnsibleUndefinedVariable(e)
|
raise AnsibleUndefinedVariable(e)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -45,6 +45,6 @@ def makedirs_safe(path, mode=None):
|
||||||
os.makedirs(path, mode)
|
os.makedirs(path, mode)
|
||||||
else:
|
else:
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
if e.errno != EEXIST:
|
if e.errno != EEXIST:
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -242,7 +242,7 @@ class VariableManager:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise AnsibleError("vars file %s was not found" % vars_file_item)
|
raise AnsibleError("vars file %s was not found" % vars_file_item)
|
||||||
except UndefinedError, e:
|
except UndefinedError as e:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not C.DEFAULT_PRIVATE_ROLE_VARS:
|
if not C.DEFAULT_PRIVATE_ROLE_VARS:
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -26,7 +26,7 @@ whitelist_externals = make
|
||||||
[testenv:py34]
|
[testenv:py34]
|
||||||
commands =
|
commands =
|
||||||
python --version
|
python --version
|
||||||
python -m compileall -fq -x 'lib/ansible/module_utils' lib test contrib
|
python -m compileall -fq -x 'lib/ansible/module_utils|lib/ansible/modules' lib test contrib
|
||||||
make tests
|
make tests
|
||||||
deps = -r{toxinidir}/test-requirements.txt
|
deps = -r{toxinidir}/test-requirements.txt
|
||||||
whitelist_externals = make
|
whitelist_externals = make
|
||||||
|
|
Loading…
Add table
Reference in a new issue