mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-03 12:44:22 -07: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:
parent
5147e792d3
commit
3fba006207
320 changed files with 659 additions and 656 deletions
|
@ -62,7 +62,7 @@ def api_get(link, config):
|
|||
result = open_url(url, headers=headers, url_username=config.get('auth', 'apiuser').replace('\n', ''),
|
||||
url_password=config.get('auth', 'apipass').replace('\n', ''))
|
||||
return json.loads(result.read())
|
||||
except:
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
|
@ -99,7 +99,7 @@ def cache_available(config):
|
|||
|
||||
try:
|
||||
existing = os.stat('/'.join([dpath, 'inventory']))
|
||||
except:
|
||||
except Exception:
|
||||
# cache doesn't exist or isn't accessible
|
||||
return False
|
||||
|
||||
|
|
|
@ -463,38 +463,38 @@ class AosInventory(object):
|
|||
# Try to reach all parameters from File, if not available try from ENV
|
||||
try:
|
||||
self.aos_server = config.get('aos', 'aos_server')
|
||||
except:
|
||||
except Exception:
|
||||
if 'AOS_SERVER' in os.environ.keys():
|
||||
self.aos_server = os.environ['AOS_SERVER']
|
||||
|
||||
try:
|
||||
self.aos_server_port = config.get('aos', 'port')
|
||||
except:
|
||||
except Exception:
|
||||
if 'AOS_PORT' in os.environ.keys():
|
||||
self.aos_server_port = os.environ['AOS_PORT']
|
||||
|
||||
try:
|
||||
self.aos_username = config.get('aos', 'username')
|
||||
except:
|
||||
except Exception:
|
||||
if 'AOS_USERNAME' in os.environ.keys():
|
||||
self.aos_username = os.environ['AOS_USERNAME']
|
||||
|
||||
try:
|
||||
self.aos_password = config.get('aos', 'password')
|
||||
except:
|
||||
except Exception:
|
||||
if 'AOS_PASSWORD' in os.environ.keys():
|
||||
self.aos_password = os.environ['AOS_PASSWORD']
|
||||
|
||||
try:
|
||||
self.aos_blueprint = config.get('aos', 'blueprint')
|
||||
except:
|
||||
except Exception:
|
||||
if 'AOS_BLUEPRINT' in os.environ.keys():
|
||||
self.aos_blueprint = os.environ['AOS_BLUEPRINT']
|
||||
|
||||
try:
|
||||
if config.get('aos', 'blueprint_interface') in ['false', 'no']:
|
||||
self.aos_blueprint_int = False
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def parse_cli_args(self):
|
||||
|
|
|
@ -397,7 +397,7 @@ class AzureRM(object):
|
|||
for key in AZURE_CREDENTIAL_ENV_MAPPING:
|
||||
try:
|
||||
credentials[key] = config.get(profile, key, raw=True)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if credentials.get('client_id') is not None or credentials.get('ad_user') is not None:
|
||||
|
@ -921,7 +921,7 @@ class AzureInventory(object):
|
|||
try:
|
||||
config = cp.ConfigParser()
|
||||
config.read(path)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if config is not None:
|
||||
|
@ -929,7 +929,7 @@ class AzureInventory(object):
|
|||
for key in AZURE_CONFIG_SETTINGS:
|
||||
try:
|
||||
settings[key] = config.get('azure', key, raw=True)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return settings
|
||||
|
|
|
@ -88,7 +88,7 @@ import json
|
|||
|
||||
try:
|
||||
import libbrook
|
||||
except:
|
||||
except Exception:
|
||||
sys.exit('Brook.io inventory script requires libbrook. See https://github.com/doalitic/libbrook')
|
||||
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ class CollinsInventory(object):
|
|||
break
|
||||
cur_page += 1
|
||||
num_retries = 0
|
||||
except:
|
||||
except Exception:
|
||||
self.log.error("Error while communicating with Collins, retrying:\n%s", traceback.format_exc())
|
||||
num_retries += 1
|
||||
return assets
|
||||
|
@ -277,7 +277,7 @@ class CollinsInventory(object):
|
|||
# Locates all server assets from Collins.
|
||||
try:
|
||||
server_assets = self.find_assets()
|
||||
except:
|
||||
except Exception:
|
||||
self.log.error("Error while locating assets from Collins:\n%s", traceback.format_exc())
|
||||
return False
|
||||
|
||||
|
@ -288,7 +288,7 @@ class CollinsInventory(object):
|
|||
ip_index = self._asset_get_attribute(asset, 'ANSIBLE_IP_INDEX')
|
||||
try:
|
||||
ip_index = int(ip_index)
|
||||
except:
|
||||
except Exception:
|
||||
self.log.error(
|
||||
"ANSIBLE_IP_INDEX attribute on asset %s not an integer: %s", asset,
|
||||
ip_index)
|
||||
|
@ -350,7 +350,7 @@ class CollinsInventory(object):
|
|||
try:
|
||||
self.write_to_cache(self.cache, self.cache_path_cache)
|
||||
self.write_to_cache(self.inventory, self.cache_path_inventory)
|
||||
except:
|
||||
except Exception:
|
||||
self.log.error("Error while writing to cache:\n%s", traceback.format_exc())
|
||||
return False
|
||||
return True
|
||||
|
@ -388,7 +388,7 @@ class CollinsInventory(object):
|
|||
json_inventory = cache.read()
|
||||
self.inventory = json.loads(json_inventory)
|
||||
return True
|
||||
except:
|
||||
except Exception:
|
||||
self.log.error("Error while loading inventory:\n%s",
|
||||
traceback.format_exc())
|
||||
self.inventory = {}
|
||||
|
@ -402,7 +402,7 @@ class CollinsInventory(object):
|
|||
json_cache = cache.read()
|
||||
self.cache = json.loads(json_cache)
|
||||
return True
|
||||
except:
|
||||
except Exception:
|
||||
self.log.error("Error while loading host cache:\n%s",
|
||||
traceback.format_exc())
|
||||
self.cache = {}
|
||||
|
|
|
@ -335,7 +335,7 @@ class ConsulInventory(object):
|
|||
metadata = json.loads(metadata['Value'])
|
||||
for k, v in metadata.items():
|
||||
self.add_metadata(node_data, k, v)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def load_groups_from_kv(self, node_data):
|
||||
|
|
|
@ -364,7 +364,7 @@ from collections import defaultdict
|
|||
for path in [os.getcwd(), '', os.path.dirname(os.path.abspath(__file__))]:
|
||||
try:
|
||||
del sys.path[sys.path.index(path)]
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
HAS_DOCKER_PY = True
|
||||
|
|
|
@ -107,7 +107,7 @@ try:
|
|||
from libcloud.compute.types import Provider
|
||||
from libcloud.compute.providers import get_driver
|
||||
_ = Provider.GCE
|
||||
except:
|
||||
except Exception:
|
||||
sys.exit("GCE inventory script requires libcloud >= 0.13")
|
||||
|
||||
|
||||
|
@ -289,7 +289,7 @@ class GceInventory(object):
|
|||
args = list(secrets.GCE_PARAMS)
|
||||
kwargs = secrets.GCE_KEYWORD_PARAMS
|
||||
secrets_found = True
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not secrets_found and secrets_path:
|
||||
|
@ -303,7 +303,7 @@ class GceInventory(object):
|
|||
args = list(getattr(secrets, 'GCE_PARAMS', []))
|
||||
kwargs = getattr(secrets, 'GCE_KEYWORD_PARAMS', {})
|
||||
secrets_found = True
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not secrets_found:
|
||||
|
|
|
@ -88,7 +88,7 @@ try:
|
|||
from chube import api as chube_api
|
||||
from chube.datacenter import Datacenter
|
||||
from chube.linode_obj import Linode
|
||||
except:
|
||||
except Exception:
|
||||
try:
|
||||
# remove local paths and other stuff that may
|
||||
# cause an import conflict, as chube is sensitive
|
||||
|
|
|
@ -29,7 +29,7 @@ import sys
|
|||
import json
|
||||
try:
|
||||
import configparser
|
||||
except:
|
||||
except Exception:
|
||||
from six.moves import configparser
|
||||
|
||||
# Set up defaults
|
||||
|
|
|
@ -254,7 +254,7 @@ class NSoTInventory(object):
|
|||
obj[group]['vars'] = hostvars
|
||||
try:
|
||||
assert isinstance(query, string_types)
|
||||
except:
|
||||
except Exception:
|
||||
sys.exit('ERR: Group queries must be a single string\n'
|
||||
' Group: %s\n'
|
||||
' Query: %s\n' % (group, query)
|
||||
|
|
|
@ -69,7 +69,7 @@ def parse_args():
|
|||
try:
|
||||
# check if rackhd url(ie:10.1.1.45:8080) is specified in the environment
|
||||
RACKHD_URL = 'http://' + str(os.environ['RACKHD_URL'])
|
||||
except:
|
||||
except Exception:
|
||||
# use default values
|
||||
pass
|
||||
|
||||
|
@ -81,7 +81,7 @@ if (parse_args().host):
|
|||
try:
|
||||
nodeids += parse_args().host.split(',')
|
||||
RackhdInventory(nodeids)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
if (parse_args().list):
|
||||
try:
|
||||
|
@ -92,5 +92,5 @@ if (parse_args().list):
|
|||
if entry['type'] == 'compute':
|
||||
nodeids.append(entry['id'])
|
||||
RackhdInventory(nodeids)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
|
|
@ -242,7 +242,7 @@ def _list_into_cache(regions):
|
|||
# pylint: disable=unexpected-keyword-arg
|
||||
ip_versions = map(int, get_config(p, 'rax', 'access_ip_version',
|
||||
'RAX_ACCESS_IP_VERSION', 4, islist=True))
|
||||
except:
|
||||
except Exception:
|
||||
ip_versions = [4]
|
||||
else:
|
||||
ip_versions = [v for v in ip_versions if v in [4, 6]]
|
||||
|
|
|
@ -258,7 +258,7 @@ class RudderInventory(object):
|
|||
|
||||
try:
|
||||
response, content = self.conn.request(target.geturl(), method, body, headers)
|
||||
except:
|
||||
except Exception:
|
||||
self.fail_with_error('Error connecting to Rudder server')
|
||||
|
||||
try:
|
||||
|
|
|
@ -53,7 +53,7 @@ import json
|
|||
|
||||
try:
|
||||
import requests
|
||||
except:
|
||||
except Exception:
|
||||
sys.exit('requests package is required for this inventory script')
|
||||
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ def get_hosts(host=None):
|
|||
else:
|
||||
returned = {'all': set(), '_metadata': {}}
|
||||
p = Popen([VBOX, 'list', '-l', 'vms'], stdout=PIPE)
|
||||
except:
|
||||
except Exception:
|
||||
sys.exit(1)
|
||||
|
||||
hostvars = {}
|
||||
|
@ -50,7 +50,7 @@ def get_hosts(host=None):
|
|||
|
||||
try:
|
||||
k, v = line.split(':', 1)
|
||||
except:
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
if k == '':
|
||||
|
@ -67,7 +67,7 @@ def get_hosts(host=None):
|
|||
if 'Value' in ipinfo:
|
||||
a, ip = ipinfo.split(':', 1)
|
||||
hostvars[curname]['ansible_ssh_host'] = ip.strip()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
continue
|
||||
|
|
|
@ -45,7 +45,7 @@ except ImportError:
|
|||
|
||||
try:
|
||||
from zabbix_api import ZabbixAPI
|
||||
except:
|
||||
except Exception:
|
||||
print("Error: Zabbix API library must be installed: pip install zabbix-api.",
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
|
|
@ -305,7 +305,7 @@ class AzureRM(object):
|
|||
for key in AZURE_CREDENTIAL_ENV_MAPPING:
|
||||
try:
|
||||
credentials[key] = config.get(profile, key, raw=True)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if credentials.get('client_id') is not None or credentials.get('ad_user') is not None:
|
||||
|
@ -571,7 +571,7 @@ class AzureKeyVaultSecret:
|
|||
try:
|
||||
config = cp.ConfigParser()
|
||||
config.read(path)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if config is not None:
|
||||
|
@ -579,7 +579,7 @@ class AzureKeyVaultSecret:
|
|||
for key in AZURE_VAULT_SETTINGS:
|
||||
try:
|
||||
settings[key] = config.get('azure_keyvault', key, raw=True)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return settings
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue