mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Update bare exceptions to specify Exception.
This will keep us from accidentally catching program-exiting exceptions like KeyboardInterupt and SystemExit.
This commit is contained in:
@@ -55,7 +55,7 @@ class ActionModule(ActionBase):
|
||||
|
||||
try:
|
||||
name, port = parse_address(new_name, allow_ranges=False)
|
||||
except:
|
||||
except Exception:
|
||||
# not a parsable hostname, but might still be usable
|
||||
name = new_name
|
||||
port = None
|
||||
|
||||
@@ -32,7 +32,7 @@ from ansible.utils.display import Display
|
||||
|
||||
try:
|
||||
from library.module_utils.network.f5.common import f5_provider_spec
|
||||
except:
|
||||
except Exception:
|
||||
from ansible.module_utils.network.f5.common import f5_provider_spec
|
||||
|
||||
display = Display()
|
||||
|
||||
@@ -30,7 +30,7 @@ from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
||||
|
||||
try:
|
||||
from library.module_utils.network.f5.common import f5_provider_spec
|
||||
except:
|
||||
except Exception:
|
||||
from ansible.module_utils.network.f5.common import f5_provider_spec
|
||||
|
||||
from ansible.utils.display import Display
|
||||
|
||||
@@ -32,7 +32,7 @@ from ansible.utils.display import Display
|
||||
|
||||
try:
|
||||
from library.module_utils.network.f5.common import f5_provider_spec
|
||||
except:
|
||||
except Exception:
|
||||
from ansible.module_utils.network.f5.common import f5_provider_spec
|
||||
|
||||
display = Display()
|
||||
|
||||
@@ -47,7 +47,7 @@ class ActionModule(ActionBase):
|
||||
module = self._templar.template("{{hostvars['%s']['ansible_facts']['service_mgr']}}" % self._task.delegate_to)
|
||||
else:
|
||||
module = self._templar.template('{{ansible_facts.service_mgr}}')
|
||||
except:
|
||||
except Exception:
|
||||
pass # could not get it from template!
|
||||
|
||||
try:
|
||||
|
||||
@@ -154,7 +154,7 @@ class Connection(ConnectionBase):
|
||||
raise AnsibleError("chroot connection requires dd command in the chroot")
|
||||
try:
|
||||
stdout, stderr = p.communicate()
|
||||
except:
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
|
||||
if p.returncode != 0:
|
||||
@@ -179,7 +179,7 @@ class Connection(ConnectionBase):
|
||||
while chunk:
|
||||
out_file.write(chunk)
|
||||
chunk = p.stdout.read(BUFSIZE)
|
||||
except:
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
|
||||
stdout, stderr = p.communicate()
|
||||
|
||||
@@ -165,7 +165,7 @@ class Connection(ConnectionBase):
|
||||
raise AnsibleError("jail connection requires dd command in the jail")
|
||||
try:
|
||||
stdout, stderr = p.communicate()
|
||||
except:
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
|
||||
if p.returncode != 0:
|
||||
@@ -190,7 +190,7 @@ class Connection(ConnectionBase):
|
||||
while chunk:
|
||||
out_file.write(chunk)
|
||||
chunk = p.stdout.read(BUFSIZE)
|
||||
except:
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
|
||||
stdout, stderr = p.communicate()
|
||||
|
||||
@@ -144,7 +144,7 @@ class Connection(ConnectionBase):
|
||||
raise AnsibleError("chroot connection requires dd command in the chroot")
|
||||
try:
|
||||
stdout, stderr = p.communicate()
|
||||
except:
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
|
||||
if p.returncode != 0:
|
||||
@@ -169,7 +169,7 @@ class Connection(ConnectionBase):
|
||||
while chunk:
|
||||
out_file.write(chunk)
|
||||
chunk = p.stdout.read(BUFSIZE)
|
||||
except:
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
|
||||
stdout, stderr = p.communicate()
|
||||
|
||||
@@ -163,7 +163,7 @@ class Connection(ConnectionBase):
|
||||
raise AnsibleError("jail connection requires dd command in the jail")
|
||||
try:
|
||||
stdout, stderr = p.communicate()
|
||||
except:
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
|
||||
if p.returncode != 0:
|
||||
@@ -188,7 +188,7 @@ class Connection(ConnectionBase):
|
||||
while chunk:
|
||||
out_file.write(chunk)
|
||||
chunk = p.stdout.read(BUFSIZE)
|
||||
except:
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
|
||||
stdout, stderr = p.communicate()
|
||||
|
||||
@@ -74,7 +74,7 @@ def _6to4_query(v, vtype, value):
|
||||
|
||||
try:
|
||||
return '2002:{:02x}{:02x}:{:02x}{:02x}::1/48'.format(*numbers)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
elif v.version == 6:
|
||||
@@ -128,7 +128,7 @@ def _cidr_lookup_query(v, iplist, value):
|
||||
try:
|
||||
if v in iplist:
|
||||
return value
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ def _ipv4_query(v, value):
|
||||
if v.version == 6:
|
||||
try:
|
||||
return str(v.ipv4())
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
else:
|
||||
return value
|
||||
@@ -563,14 +563,14 @@ def ipaddr(value, query='', version=False, alias='ipaddr'):
|
||||
v.prefixlen = 128
|
||||
|
||||
# IPv4 didn't work the first time, so it definitely has to be IPv6
|
||||
except:
|
||||
except Exception:
|
||||
try:
|
||||
v = netaddr.IPNetwork('::/0')
|
||||
v.value = int(value)
|
||||
v.prefixlen = 128
|
||||
|
||||
# The value is too big for IPv6. Are you a nanobot?
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
# We got an IP address, let's mark it as such
|
||||
@@ -588,11 +588,11 @@ def ipaddr(value, query='', version=False, alias='ipaddr'):
|
||||
try:
|
||||
address, prefix = value.split('/')
|
||||
vtype = 'network'
|
||||
except:
|
||||
except Exception:
|
||||
vtype = 'address'
|
||||
|
||||
# value hasn't been recognized, maybe it's a numerical CIDR?
|
||||
except:
|
||||
except Exception:
|
||||
try:
|
||||
address, prefix = value.split('/')
|
||||
address.isdigit()
|
||||
@@ -601,7 +601,7 @@ def ipaddr(value, query='', version=False, alias='ipaddr'):
|
||||
prefix = int(prefix)
|
||||
|
||||
# It's not numerical CIDR, give up
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
# It is something, so let's try and build a CIDR from the parts
|
||||
@@ -611,14 +611,14 @@ def ipaddr(value, query='', version=False, alias='ipaddr'):
|
||||
v.prefixlen = prefix
|
||||
|
||||
# It's not a valid IPv4 CIDR
|
||||
except:
|
||||
except Exception:
|
||||
try:
|
||||
v = netaddr.IPNetwork('::/0')
|
||||
v.value = address
|
||||
v.prefixlen = prefix
|
||||
|
||||
# It's not a valid IPv6 CIDR. Give up.
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
# We have a valid CIDR, so let's write it in correct format
|
||||
@@ -633,7 +633,7 @@ def ipaddr(value, query='', version=False, alias='ipaddr'):
|
||||
if query and (query not in query_func_map or query == 'cidr_lookup') and ipaddr(query, 'network'):
|
||||
iplist = netaddr.IPSet([netaddr.IPNetwork(query)])
|
||||
query = 'cidr_lookup'
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# This code checks if value maches the IP version the user wants, ie. if
|
||||
@@ -659,13 +659,13 @@ def ipaddr(value, query='', version=False, alias='ipaddr'):
|
||||
elif v.size > 1:
|
||||
try:
|
||||
return str(v[query]) + '/' + str(v.prefixlen)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
else:
|
||||
return value
|
||||
|
||||
except:
|
||||
except Exception:
|
||||
raise errors.AnsibleFilterError(alias + ': unknown filter type: %s' % query)
|
||||
|
||||
return False
|
||||
@@ -706,7 +706,7 @@ def ipwrap(value, query=''):
|
||||
else:
|
||||
return value
|
||||
|
||||
except:
|
||||
except Exception:
|
||||
return value
|
||||
|
||||
|
||||
@@ -750,7 +750,7 @@ def ipsubnet(value, query='', index='x'):
|
||||
v = ipaddr(value, 'subnet')
|
||||
|
||||
value = netaddr.IPNetwork(v)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
query_string = str(query)
|
||||
if not query:
|
||||
@@ -767,26 +767,26 @@ def ipsubnet(value, query='', index='x'):
|
||||
if vsize > 1:
|
||||
try:
|
||||
return str(list(value.subnet(query))[index])
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
elif vsize == 1:
|
||||
try:
|
||||
return str(value.supernet(query)[index])
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
except:
|
||||
except Exception:
|
||||
if vsize > 1:
|
||||
try:
|
||||
return str(len(list(value.subnet(query))))
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
elif vsize == 1:
|
||||
try:
|
||||
return str(value.supernet(query)[0])
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
elif query_string:
|
||||
@@ -822,7 +822,7 @@ def nthhost(value, query=''):
|
||||
v = ipaddr(value, 'subnet')
|
||||
|
||||
value = netaddr.IPNetwork(v)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
if not query:
|
||||
@@ -849,7 +849,7 @@ def next_nth_usable(value, offset):
|
||||
v = ipaddr(value, 'subnet')
|
||||
|
||||
v = netaddr.IPNetwork(v)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
if type(offset) != int:
|
||||
@@ -871,7 +871,7 @@ def previous_nth_usable(value, offset):
|
||||
v = ipaddr(value, 'subnet')
|
||||
|
||||
v = netaddr.IPNetwork(v)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
if type(offset) != int:
|
||||
@@ -912,7 +912,7 @@ def _address_normalizer(value):
|
||||
vtype = ipaddr(value, 'type')
|
||||
if vtype == 'address' or vtype == "network":
|
||||
v = ipaddr(value, 'subnet')
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
return v
|
||||
@@ -1018,7 +1018,7 @@ def slaac(value, query=''):
|
||||
return False
|
||||
|
||||
value = netaddr.IPNetwork(v)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
if not query:
|
||||
@@ -1028,7 +1028,7 @@ def slaac(value, query=''):
|
||||
mac = hwaddr(query, alias='slaac')
|
||||
|
||||
eui = netaddr.EUI(mac)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
return eui.ipv6(value.network)
|
||||
@@ -1059,7 +1059,7 @@ def hwaddr(value, query='', alias='hwaddr'):
|
||||
|
||||
try:
|
||||
v = netaddr.EUI(value)
|
||||
except:
|
||||
except Exception:
|
||||
if query and query != 'bool':
|
||||
raise errors.AnsibleFilterError(alias + ': not a hardware address: %s' % value)
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ def parse_cli(output, tmpl):
|
||||
try:
|
||||
variables = spec.get('vars', {})
|
||||
value = template(value, variables)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if 'start_block' in attrs and 'end_block' in attrs:
|
||||
@@ -151,7 +151,7 @@ def parse_cli(output, tmpl):
|
||||
for k, v in iteritems(value):
|
||||
try:
|
||||
obj[k] = template(v, {'item': items}, fail_on_undefined=False)
|
||||
except:
|
||||
except Exception:
|
||||
obj[k] = None
|
||||
objects.append(obj)
|
||||
|
||||
@@ -269,7 +269,7 @@ def _extract_param(template, root, attrs, value):
|
||||
fields = None
|
||||
try:
|
||||
fields = element.findall(param_xpath)
|
||||
except:
|
||||
except Exception:
|
||||
display.warning("Failed to evaluate value of '%s' with XPath '%s'.\nUnexpected error: %s." % (param, param_xpath, traceback.format_exc()))
|
||||
|
||||
tags = param_xpath.split('/')
|
||||
@@ -339,7 +339,7 @@ def parse_xml(output, tmpl):
|
||||
try:
|
||||
variables = spec.get('vars', {})
|
||||
value = template(value, variables)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if 'items' in attrs:
|
||||
|
||||
@@ -71,7 +71,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||
if 'Value' in ipinfo:
|
||||
a, ip = ipinfo.split(':', 1)
|
||||
ret = ip.strip()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
return ret
|
||||
|
||||
@@ -137,7 +137,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||
continue
|
||||
try:
|
||||
k, v = line.split(':', 1)
|
||||
except:
|
||||
except Exception:
|
||||
# skip non splitable
|
||||
continue
|
||||
|
||||
|
||||
@@ -88,6 +88,6 @@ class LookupModule(LookupBase):
|
||||
if res is None:
|
||||
res = ""
|
||||
ret.append(res)
|
||||
except:
|
||||
except Exception:
|
||||
ret.append("") # connection failed or key not found
|
||||
return ret
|
||||
|
||||
@@ -222,7 +222,7 @@ class LookupModule(LookupBase):
|
||||
try:
|
||||
socket.inet_aton(ns)
|
||||
nameservers.append(ns)
|
||||
except:
|
||||
except Exception:
|
||||
try:
|
||||
nsaddr = dns.resolver.query(ns)[0].address
|
||||
nameservers.append(nsaddr)
|
||||
@@ -233,7 +233,7 @@ class LookupModule(LookupBase):
|
||||
if '=' in t:
|
||||
try:
|
||||
opt, arg = t.split('=')
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if opt == 'qtype':
|
||||
@@ -251,7 +251,7 @@ class LookupModule(LookupBase):
|
||||
if '/' in t:
|
||||
try:
|
||||
domain, qtype = t.split('/')
|
||||
except:
|
||||
except Exception:
|
||||
domain = t
|
||||
else:
|
||||
domain = t
|
||||
|
||||
@@ -116,7 +116,7 @@ def check_output2(*popenargs, **kwargs):
|
||||
process = subprocess.Popen(*popenargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
|
||||
try:
|
||||
b_out, b_err = process.communicate(b_inputdata)
|
||||
except:
|
||||
except Exception:
|
||||
process.kill()
|
||||
process.wait()
|
||||
raise
|
||||
|
||||
@@ -137,7 +137,7 @@ class StrategyModule(StrategyBase):
|
||||
try:
|
||||
task.name = to_text(templar.template(task.name, fail_on_undefined=False), nonstring='empty')
|
||||
display.debug("done templating", host=host_name)
|
||||
except:
|
||||
except Exception:
|
||||
# just ignore any errors during task name templating,
|
||||
# we don't care if it just shows the raw name
|
||||
display.debug("templating failed for some reason", host=host_name)
|
||||
|
||||
@@ -292,7 +292,7 @@ class StrategyModule(StrategyBase):
|
||||
try:
|
||||
task.name = to_text(templar.template(task.name, fail_on_undefined=False), nonstring='empty')
|
||||
display.debug("done templating")
|
||||
except:
|
||||
except Exception:
|
||||
# just ignore any errors during task name templating,
|
||||
# we don't care if it just shows the raw name
|
||||
display.debug("templating failed for some reason")
|
||||
|
||||
Reference in New Issue
Block a user