mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
batch 4 - update Python idiom to 3.7 using pyupgrade (#11344)
* batch 4 - update Python idiom to 3.7 using pyupgrade * add changelog frag * bring back sanity * remove unused import
This commit is contained in:
parent
5b5f7e9e64
commit
543329cecb
33 changed files with 96 additions and 64 deletions
33
changelogs/fragments/11344-pyupgrade-4.yml
Normal file
33
changelogs/fragments/11344-pyupgrade-4.yml
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
minor_changes:
|
||||||
|
- manageiq_alert_profiles - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- modprobe - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- mssql_db - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- nagios - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- nosh - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- omapi_host - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- one_vm - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- pam_limits - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- pamd - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- parted - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- pubnub_blocks - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- pulp_repo - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- read_csv - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- redhat_subscription - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- rhsm_repository - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- runit - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- sensu_check - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- sensu_client - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- sensu_handler - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- sensu_subscription - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- seport - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- serverless - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- solaris_zone - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- sorcery - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- spotinst_aws_elastigroup - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- sudoers - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- svc - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- timezone - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- wakeonlan - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- xfs_quota - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- zypper - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
- zypper_repository - update to Python 3.7 idioms (https://github.com/ansible-collections/community.general/pull/11344).
|
||||||
|
|
@ -184,7 +184,7 @@ class ManageIQAlertProfiles:
|
||||||
# alert which currently exist in the profile
|
# alert which currently exist in the profile
|
||||||
if "alert_definitions" in old_profile:
|
if "alert_definitions" in old_profile:
|
||||||
# we use get_alert_href to have a direct href to the alert
|
# we use get_alert_href to have a direct href to the alert
|
||||||
existing_alerts = set(self.get_alert_href(alert) for alert in old_profile["alert_definitions"])
|
existing_alerts = {self.get_alert_href(alert) for alert in old_profile["alert_definitions"]}
|
||||||
else:
|
else:
|
||||||
# no alerts in this profile
|
# no alerts in this profile
|
||||||
existing_alerts = set()
|
existing_alerts = set()
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ class Modprobe:
|
||||||
if line.rstrip().endswith(module_file):
|
if line.rstrip().endswith(module_file):
|
||||||
is_loaded = True
|
is_loaded = True
|
||||||
break
|
break
|
||||||
except (IOError, OSError) as e:
|
except OSError as e:
|
||||||
self.module.fail_json(msg=f"{e}", exception=traceback.format_exc(), **self.result)
|
self.module.fail_json(msg=f"{e}", exception=traceback.format_exc(), **self.result)
|
||||||
|
|
||||||
return is_loaded
|
return is_loaded
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ def db_delete(conn, cursor, db):
|
||||||
|
|
||||||
def db_import(conn, cursor, module, db, target):
|
def db_import(conn, cursor, module, db, target):
|
||||||
if os.path.isfile(target):
|
if os.path.isfile(target):
|
||||||
with open(target, "r") as backup:
|
with open(target) as backup:
|
||||||
sqlQuery = f"USE [{db}]\n"
|
sqlQuery = f"USE [{db}]\n"
|
||||||
for line in backup:
|
for line in backup:
|
||||||
if line is None:
|
if line is None:
|
||||||
|
|
|
||||||
|
|
@ -422,7 +422,7 @@ class Nagios:
|
||||||
fp.write(cmd)
|
fp.write(cmd)
|
||||||
fp.flush()
|
fp.flush()
|
||||||
self.command_results.append(cmd.strip())
|
self.command_results.append(cmd.strip())
|
||||||
except IOError:
|
except OSError:
|
||||||
self.module.fail_json(msg="unable to write to nagios command file", cmdfile=self.cmdfile)
|
self.module.fail_json(msg="unable to write to nagios command file", cmdfile=self.cmdfile)
|
||||||
|
|
||||||
def _fmt_dt_str(self, cmd, host, duration, author=None, comment=None, start=None, svc=None, fixed=1, trigger=0):
|
def _fmt_dt_str(self, cmd, host, duration, author=None, comment=None, start=None, svc=None, fixed=1, trigger=0):
|
||||||
|
|
|
||||||
|
|
@ -371,7 +371,7 @@ def get_service_status(module, service_path):
|
||||||
|
|
||||||
|
|
||||||
def service_is_running(service_status):
|
def service_is_running(service_status):
|
||||||
return service_status["DaemontoolsEncoreState"] in set(["starting", "started", "running"])
|
return service_status["DaemontoolsEncoreState"] in {"starting", "started", "running"}
|
||||||
|
|
||||||
|
|
||||||
def handle_enabled(module, result, service_path):
|
def handle_enabled(module, result, service_path):
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,6 @@ lease:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import binascii
|
import binascii
|
||||||
import socket
|
|
||||||
import struct
|
import struct
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
|
@ -168,7 +167,7 @@ class OmapiHostManager:
|
||||||
self.module.fail_json(
|
self.module.fail_json(
|
||||||
msg=f"Unable to open OMAPI connection. Ensure 'host', 'port', 'key' and 'key_name' are valid. Exception was: {e}"
|
msg=f"Unable to open OMAPI connection. Ensure 'host', 'port', 'key' and 'key_name' are valid. Exception was: {e}"
|
||||||
)
|
)
|
||||||
except socket.error as e:
|
except OSError as e:
|
||||||
self.module.fail_json(msg=f"Unable to connect to OMAPI server: {e}")
|
self.module.fail_json(msg=f"Unable to connect to OMAPI server: {e}")
|
||||||
|
|
||||||
def get_host(self, macaddr):
|
def get_host(self, macaddr):
|
||||||
|
|
|
||||||
|
|
@ -1628,11 +1628,11 @@ def get_connection_info(module):
|
||||||
if authfile is None:
|
if authfile is None:
|
||||||
authfile = os.path.join(os.environ.get("HOME"), ".one", "one_auth")
|
authfile = os.path.join(os.environ.get("HOME"), ".one", "one_auth")
|
||||||
try:
|
try:
|
||||||
with open(authfile, "r") as fp:
|
with open(authfile) as fp:
|
||||||
authstring = fp.read().rstrip()
|
authstring = fp.read().rstrip()
|
||||||
username = authstring.split(":")[0]
|
username = authstring.split(":")[0]
|
||||||
password = authstring.split(":")[1]
|
password = authstring.split(":")[1]
|
||||||
except (OSError, IOError):
|
except OSError:
|
||||||
module.fail_json(msg=f"Could not find or read ONE_AUTH file at '{authfile}'")
|
module.fail_json(msg=f"Could not find or read ONE_AUTH file at '{authfile}'")
|
||||||
except Exception:
|
except Exception:
|
||||||
module.fail_json(msg=f"Error occurs when read ONE_AUTH file at '{authfile}'")
|
module.fail_json(msg=f"Error occurs when read ONE_AUTH file at '{authfile}'")
|
||||||
|
|
|
||||||
|
|
@ -348,7 +348,7 @@ def main():
|
||||||
|
|
||||||
nf.flush()
|
nf.flush()
|
||||||
|
|
||||||
with open(nf.name, "r") as content:
|
with open(nf.name) as content:
|
||||||
content_new = content.read()
|
content_new = content.read()
|
||||||
|
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
|
|
|
||||||
|
|
@ -787,9 +787,9 @@ def main():
|
||||||
|
|
||||||
# Open the file and read the content or fail
|
# Open the file and read the content or fail
|
||||||
try:
|
try:
|
||||||
with open(fname, "r") as service_file_obj:
|
with open(fname) as service_file_obj:
|
||||||
content = service_file_obj.read()
|
content = service_file_obj.read()
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
# If unable to read the file, fail out
|
# If unable to read the file, fail out
|
||||||
module.fail_json(msg=f"Unable to open/read PAM module file {fname} with error {e}.")
|
module.fail_json(msg=f"Unable to open/read PAM module file {fname} with error {e}.")
|
||||||
|
|
||||||
|
|
@ -875,7 +875,7 @@ def main():
|
||||||
with open(temp_file.name, "w") as fd:
|
with open(temp_file.name, "w") as fd:
|
||||||
fd.write(str(service))
|
fd.write(str(service))
|
||||||
|
|
||||||
except IOError:
|
except OSError:
|
||||||
module.fail_json(msg=f"Unable to create temporary file {temp_file}")
|
module.fail_json(msg=f"Unable to create temporary file {temp_file}")
|
||||||
|
|
||||||
module.atomic_move(temp_file.name, os.path.realpath(fname))
|
module.atomic_move(temp_file.name, os.path.realpath(fname))
|
||||||
|
|
|
||||||
|
|
@ -569,9 +569,9 @@ def read_record(file_path, default=None):
|
||||||
Reads the first line of a file and returns it.
|
Reads the first line of a file and returns it.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with open(file_path, "r") as f:
|
with open(file_path) as f:
|
||||||
return f.readline().strip()
|
return f.readline().strip()
|
||||||
except IOError:
|
except OSError:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -512,7 +512,7 @@ def _content_of_file_at_path(path):
|
||||||
"""
|
"""
|
||||||
content = None
|
content = None
|
||||||
if path and os.path.exists(path):
|
if path and os.path.exists(path):
|
||||||
with open(path, mode="rt") as opened_file:
|
with open(path) as opened_file:
|
||||||
b_content = opened_file.read()
|
b_content = opened_file.read()
|
||||||
try:
|
try:
|
||||||
content = to_text(b_content, errors="surrogate_or_strict")
|
content = to_text(b_content, errors="surrogate_or_strict")
|
||||||
|
|
|
||||||
|
|
@ -541,19 +541,19 @@ def main():
|
||||||
if importer_ssl_ca_cert is not None:
|
if importer_ssl_ca_cert is not None:
|
||||||
importer_ssl_ca_cert_file_path = os.path.abspath(importer_ssl_ca_cert)
|
importer_ssl_ca_cert_file_path = os.path.abspath(importer_ssl_ca_cert)
|
||||||
if os.path.isfile(importer_ssl_ca_cert_file_path):
|
if os.path.isfile(importer_ssl_ca_cert_file_path):
|
||||||
with open(importer_ssl_ca_cert_file_path, "r") as importer_ssl_ca_cert_file_object:
|
with open(importer_ssl_ca_cert_file_path) as importer_ssl_ca_cert_file_object:
|
||||||
importer_ssl_ca_cert = importer_ssl_ca_cert_file_object.read()
|
importer_ssl_ca_cert = importer_ssl_ca_cert_file_object.read()
|
||||||
|
|
||||||
if importer_ssl_client_cert is not None:
|
if importer_ssl_client_cert is not None:
|
||||||
importer_ssl_client_cert_file_path = os.path.abspath(importer_ssl_client_cert)
|
importer_ssl_client_cert_file_path = os.path.abspath(importer_ssl_client_cert)
|
||||||
if os.path.isfile(importer_ssl_client_cert_file_path):
|
if os.path.isfile(importer_ssl_client_cert_file_path):
|
||||||
with open(importer_ssl_client_cert_file_path, "r") as importer_ssl_client_cert_file_object:
|
with open(importer_ssl_client_cert_file_path) as importer_ssl_client_cert_file_object:
|
||||||
importer_ssl_client_cert = importer_ssl_client_cert_file_object.read()
|
importer_ssl_client_cert = importer_ssl_client_cert_file_object.read()
|
||||||
|
|
||||||
if importer_ssl_client_key is not None:
|
if importer_ssl_client_key is not None:
|
||||||
importer_ssl_client_key_file_path = os.path.abspath(importer_ssl_client_key)
|
importer_ssl_client_key_file_path = os.path.abspath(importer_ssl_client_key)
|
||||||
if os.path.isfile(importer_ssl_client_key_file_path):
|
if os.path.isfile(importer_ssl_client_key_file_path):
|
||||||
with open(importer_ssl_client_key_file_path, "r") as importer_ssl_client_key_file_object:
|
with open(importer_ssl_client_key_file_path) as importer_ssl_client_key_file_object:
|
||||||
importer_ssl_client_key = importer_ssl_client_key_file_object.read()
|
importer_ssl_client_key = importer_ssl_client_key_file_object.read()
|
||||||
|
|
||||||
server = pulp_server(module, pulp_host, repo_type, wait_for_completion=wait_for_completion)
|
server = pulp_server(module, pulp_host, repo_type, wait_for_completion=wait_for_completion)
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
except (IOError, OSError) as e:
|
except OSError as e:
|
||||||
module.fail_json(msg=f"Unable to open file: {e}")
|
module.fail_json(msg=f"Unable to open file: {e}")
|
||||||
|
|
||||||
reader = read_csv(data, dialect, fieldnames)
|
reader = read_csv(data, dialect, fieldnames)
|
||||||
|
|
|
||||||
|
|
@ -1034,9 +1034,9 @@ class SysPurpose:
|
||||||
"""
|
"""
|
||||||
current_syspurpose = {}
|
current_syspurpose = {}
|
||||||
try:
|
try:
|
||||||
with open(self.path, "r") as fp:
|
with open(self.path) as fp:
|
||||||
content = fp.read()
|
content = fp.read()
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
current_syspurpose = json.loads(content)
|
current_syspurpose = json.loads(content)
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,7 @@ def repository_modify(module, rhsm, state, name, purge=False):
|
||||||
# Disable all enabled repos on the system that are not in the task and not
|
# Disable all enabled repos on the system that are not in the task and not
|
||||||
# marked as disabled by the task
|
# marked as disabled by the task
|
||||||
if purge:
|
if purge:
|
||||||
enabled_repo_ids = set(repo["id"] for repo in updated_repo_list if repo["enabled"])
|
enabled_repo_ids = {repo["id"] for repo in updated_repo_list if repo["enabled"]}
|
||||||
matched_repoids_set = set(matched_existing_repo.keys())
|
matched_repoids_set = set(matched_existing_repo.keys())
|
||||||
difference = enabled_repo_ids.difference(matched_repoids_set)
|
difference = enabled_repo_ids.difference(matched_repoids_set)
|
||||||
if len(difference) > 0:
|
if len(difference) > 0:
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ def main():
|
||||||
sv.enable()
|
sv.enable()
|
||||||
else:
|
else:
|
||||||
sv.disable()
|
sv.disable()
|
||||||
except (OSError, IOError) as e:
|
except OSError as e:
|
||||||
module.fail_json(msg=f"Could not change service link: {e}")
|
module.fail_json(msg=f"Could not change service link: {e}")
|
||||||
|
|
||||||
if state is not None and state != sv.state:
|
if state is not None and state != sv.state:
|
||||||
|
|
|
||||||
|
|
@ -193,9 +193,9 @@ def sensu_check(module, path, name, state="present", backup=False):
|
||||||
stream = None
|
stream = None
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
stream = open(path, "r")
|
stream = open(path)
|
||||||
config = json.load(stream)
|
config = json.load(stream)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == 2: # File not found, non-fatal
|
if e.errno == 2: # File not found, non-fatal
|
||||||
if state == "absent":
|
if state == "absent":
|
||||||
reasons.append("file did not exist and state is `absent'")
|
reasons.append("file did not exist and state is `absent'")
|
||||||
|
|
@ -323,7 +323,7 @@ def sensu_check(module, path, name, state="present", backup=False):
|
||||||
try:
|
try:
|
||||||
stream = open(path, "w")
|
stream = open(path, "w")
|
||||||
stream.write(json.dumps(config, indent=2) + "\n")
|
stream.write(json.dumps(config, indent=2) + "\n")
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
module.fail_json(msg=f"{e}", exception=traceback.format_exc())
|
module.fail_json(msg=f"{e}", exception=traceback.format_exc())
|
||||||
finally:
|
finally:
|
||||||
if stream:
|
if stream:
|
||||||
|
|
|
||||||
|
|
@ -252,8 +252,8 @@ def main():
|
||||||
# Load the current config, if there is one, so we can compare
|
# Load the current config, if there is one, so we can compare
|
||||||
current_config = None
|
current_config = None
|
||||||
try:
|
try:
|
||||||
current_config = json.load(open(path, "r"))
|
current_config = json.load(open(path))
|
||||||
except (IOError, ValueError):
|
except (OSError, ValueError):
|
||||||
# File either doesn't exist or it is invalid JSON
|
# File either doesn't exist or it is invalid JSON
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -277,7 +277,7 @@ def main():
|
||||||
with open(path, "w") as client:
|
with open(path, "w") as client:
|
||||||
client.write(json.dumps(config, indent=4))
|
client.write(json.dumps(config, indent=4))
|
||||||
module.exit_json(msg="Client configuration updated", changed=True, config=config["client"], file=path)
|
module.exit_json(msg="Client configuration updated", changed=True, config=config["client"], file=path)
|
||||||
except (OSError, IOError) as e:
|
except OSError as e:
|
||||||
module.fail_json(msg=f"Unable to write file {path}: {e}")
|
module.fail_json(msg=f"Unable to write file {path}: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -252,8 +252,8 @@ def main():
|
||||||
# Load the current config, if there is one, so we can compare
|
# Load the current config, if there is one, so we can compare
|
||||||
current_config = None
|
current_config = None
|
||||||
try:
|
try:
|
||||||
current_config = json.load(open(path, "r"))
|
current_config = json.load(open(path))
|
||||||
except (IOError, ValueError):
|
except (OSError, ValueError):
|
||||||
# File either doesn't exist or it is invalid JSON
|
# File either doesn't exist or it is invalid JSON
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -285,7 +285,7 @@ def main():
|
||||||
module.exit_json(
|
module.exit_json(
|
||||||
msg="Handler configuration updated", changed=True, config=config["handlers"][name], file=path, name=name
|
msg="Handler configuration updated", changed=True, config=config["handlers"][name], file=path, name=name
|
||||||
)
|
)
|
||||||
except (OSError, IOError) as e:
|
except OSError as e:
|
||||||
module.fail_json(msg=f"Unable to write file {path}: {e}")
|
module.fail_json(msg=f"Unable to write file {path}: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ def sensu_subscription(module, path, name, state="present", backup=False):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = json.load(open(path))
|
config = json.load(open(path))
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == 2: # File not found, non-fatal
|
if e.errno == 2: # File not found, non-fatal
|
||||||
if state == "absent":
|
if state == "absent":
|
||||||
reasons.append("file did not exist and state is 'absent'")
|
reasons.append("file did not exist and state is 'absent'")
|
||||||
|
|
@ -126,7 +126,7 @@ def sensu_subscription(module, path, name, state="present", backup=False):
|
||||||
module.backup_local(path)
|
module.backup_local(path)
|
||||||
try:
|
try:
|
||||||
open(path, "w").write(json.dumps(config, indent=2) + "\n")
|
open(path, "w").write(json.dumps(config, indent=2) + "\n")
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
module.fail_json(msg=f"Failed to write to file {path}: {e}", exception=traceback.format_exc())
|
module.fail_json(msg=f"Failed to write to file {path}: {e}", exception=traceback.format_exc())
|
||||||
|
|
||||||
return changed, reasons
|
return changed, reasons
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ def semanage_port_add(module, ports, proto, setype, do_reload, serange="s0", ses
|
||||||
else:
|
else:
|
||||||
seport.modify(port, proto, serange, setype)
|
seport.modify(port, proto, serange, setype)
|
||||||
|
|
||||||
except (ValueError, IOError, KeyError, OSError, RuntimeError) as e:
|
except (ValueError, OSError, KeyError, RuntimeError) as e:
|
||||||
module.fail_json(msg=f"{e.__class__.__name__}: {e}\n", exception=traceback.format_exc())
|
module.fail_json(msg=f"{e.__class__.__name__}: {e}\n", exception=traceback.format_exc())
|
||||||
|
|
||||||
return change
|
return change
|
||||||
|
|
@ -270,7 +270,7 @@ def semanage_port_del(module, ports, proto, setype, do_reload, sestore="", local
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
seport.delete(port, proto)
|
seport.delete(port, proto)
|
||||||
|
|
||||||
except (ValueError, IOError, KeyError, OSError, RuntimeError) as e:
|
except (ValueError, OSError, KeyError, RuntimeError) as e:
|
||||||
module.fail_json(msg=f"{e.__class__.__name__}: {e}\n", exception=traceback.format_exc())
|
module.fail_json(msg=f"{e.__class__.__name__}: {e}\n", exception=traceback.format_exc())
|
||||||
|
|
||||||
return change
|
return change
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ def read_serverless_config(module):
|
||||||
with open(full_path) as sls_config:
|
with open(full_path) as sls_config:
|
||||||
config = yaml.safe_load(sls_config.read())
|
config = yaml.safe_load(sls_config.read())
|
||||||
return config
|
return config
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
module.fail_json(msg=f"Could not open serverless.yml in {full_path}. err: {e}")
|
module.fail_json(msg=f"Could not open serverless.yml in {full_path}. err: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -282,7 +282,7 @@ class Zone:
|
||||||
def configure_password(self):
|
def configure_password(self):
|
||||||
shadow = f"{self.path}/root/etc/shadow"
|
shadow = f"{self.path}/root/etc/shadow"
|
||||||
if self.root_password:
|
if self.root_password:
|
||||||
with open(shadow, "r") as f:
|
with open(shadow) as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
|
||||||
for i in range(0, len(lines)):
|
for i in range(0, len(lines)):
|
||||||
|
|
|
||||||
|
|
@ -369,7 +369,7 @@ def match_depends(module):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
shutil.copy2(sorcery_depends_orig, sorcery_depends)
|
shutil.copy2(sorcery_depends_orig, sorcery_depends)
|
||||||
except IOError:
|
except OSError:
|
||||||
module.fail_json(msg="failed to copy depends.check file")
|
module.fail_json(msg="failed to copy depends.check file")
|
||||||
else:
|
else:
|
||||||
sorcery_depends = os.path.join(SORCERY_STATE_DIR, "depends")
|
sorcery_depends = os.path.join(SORCERY_STATE_DIR, "depends")
|
||||||
|
|
@ -441,7 +441,7 @@ def match_depends(module):
|
||||||
sys.stdout.write(line)
|
sys.stdout.write(line)
|
||||||
else:
|
else:
|
||||||
sys.stdout.write(line)
|
sys.stdout.write(line)
|
||||||
except IOError:
|
except OSError:
|
||||||
module.fail_json(msg="I/O error on the depends file")
|
module.fail_json(msg="I/O error on the depends file")
|
||||||
finally:
|
finally:
|
||||||
fi.close()
|
fi.close()
|
||||||
|
|
@ -453,7 +453,7 @@ def match_depends(module):
|
||||||
with open(sorcery_depends, "a") as fl:
|
with open(sorcery_depends, "a") as fl:
|
||||||
for k in depends_new:
|
for k in depends_new:
|
||||||
fl.write(f"{spell}:{k}:{depends[k]}:optional::\n")
|
fl.write(f"{spell}:{k}:{depends[k]}:optional::\n")
|
||||||
except IOError:
|
except OSError:
|
||||||
module.fail_json(msg="I/O error on the depends file")
|
module.fail_json(msg="I/O error on the depends file")
|
||||||
|
|
||||||
depends_ok = False
|
depends_ok = False
|
||||||
|
|
@ -461,7 +461,7 @@ def match_depends(module):
|
||||||
if module.check_mode:
|
if module.check_mode:
|
||||||
try:
|
try:
|
||||||
os.remove(sorcery_depends)
|
os.remove(sorcery_depends)
|
||||||
except IOError:
|
except OSError:
|
||||||
module.fail_json(msg="failed to clean up depends.backup file")
|
module.fail_json(msg="failed to clean up depends.backup file")
|
||||||
|
|
||||||
return depends_ok
|
return depends_ok
|
||||||
|
|
@ -545,7 +545,7 @@ def manage_spells(module):
|
||||||
# back up original queue
|
# back up original queue
|
||||||
try:
|
try:
|
||||||
os.rename(sorcery_queue, f"{sorcery_queue}.backup")
|
os.rename(sorcery_queue, f"{sorcery_queue}.backup")
|
||||||
except IOError:
|
except OSError:
|
||||||
module.fail_json(msg="failed to backup the update queue")
|
module.fail_json(msg="failed to backup the update queue")
|
||||||
|
|
||||||
# see update_codex()
|
# see update_codex()
|
||||||
|
|
@ -567,7 +567,7 @@ def manage_spells(module):
|
||||||
if module.check_mode:
|
if module.check_mode:
|
||||||
try:
|
try:
|
||||||
os.rename(f"{sorcery_queue}.backup", sorcery_queue)
|
os.rename(f"{sorcery_queue}.backup", sorcery_queue)
|
||||||
except IOError:
|
except OSError:
|
||||||
module.fail_json(msg="failed to restore the update queue")
|
module.fail_json(msg="failed to restore the update queue")
|
||||||
|
|
||||||
return (True, "would have updated the system")
|
return (True, "would have updated the system")
|
||||||
|
|
|
||||||
|
|
@ -1434,13 +1434,13 @@ def main():
|
||||||
credentials_path = module.params.get("credentials_path")
|
credentials_path = module.params.get("credentials_path")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(credentials_path, "r") as creds:
|
with open(credentials_path) as creds:
|
||||||
for line in creds:
|
for line in creds:
|
||||||
eq_index = line.find("=")
|
eq_index = line.find("=")
|
||||||
var_name = line[:eq_index].strip()
|
var_name = line[:eq_index].strip()
|
||||||
string_value = line[eq_index + 1 :].strip()
|
string_value = line[eq_index + 1 :].strip()
|
||||||
creds_file_loaded_vars[var_name] = string_value
|
creds_file_loaded_vars[var_name] = string_value
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
# End of creds file retrieval
|
# End of creds file retrieval
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,7 @@ class Sudoers:
|
||||||
return os.path.exists(self.file)
|
return os.path.exists(self.file)
|
||||||
|
|
||||||
def matches(self):
|
def matches(self):
|
||||||
with open(self.file, "r") as f:
|
with open(self.file) as f:
|
||||||
content_matches = f.read() == self.content()
|
content_matches = f.read() == self.content()
|
||||||
|
|
||||||
current_mode = os.stat(self.file).st_mode & 0o777
|
current_mode = os.stat(self.file).st_mode & 0o777
|
||||||
|
|
|
||||||
|
|
@ -273,7 +273,7 @@ def main():
|
||||||
svc.enable()
|
svc.enable()
|
||||||
else:
|
else:
|
||||||
svc.disable()
|
svc.disable()
|
||||||
except (OSError, IOError) as e:
|
except OSError as e:
|
||||||
module.fail_json(msg=f"Could not change service link: {e}")
|
module.fail_json(msg=f"Could not change service link: {e}")
|
||||||
|
|
||||||
if state is not None and state != svc.state:
|
if state is not None and state != svc.state:
|
||||||
|
|
@ -290,7 +290,7 @@ def main():
|
||||||
open(d_file, "a").close()
|
open(d_file, "a").close()
|
||||||
else:
|
else:
|
||||||
os.unlink(d_file)
|
os.unlink(d_file)
|
||||||
except (OSError, IOError) as e:
|
except OSError as e:
|
||||||
module.fail_json(msg=f"Could not change downed file: {e} ")
|
module.fail_json(msg=f"Could not change downed file: {e} ")
|
||||||
|
|
||||||
module.exit_json(changed=changed, svc=svc.report())
|
module.exit_json(changed=changed, svc=svc.report())
|
||||||
|
|
|
||||||
|
|
@ -376,9 +376,9 @@ class NosystemdTimezone(Timezone):
|
||||||
self.conf_files["name"] = "/etc/sysconfig/clock"
|
self.conf_files["name"] = "/etc/sysconfig/clock"
|
||||||
self.conf_files["hwclock"] = "/etc/sysconfig/clock"
|
self.conf_files["hwclock"] = "/etc/sysconfig/clock"
|
||||||
try:
|
try:
|
||||||
with open(self.conf_files["name"], "r") as f:
|
with open(self.conf_files["name"]) as f:
|
||||||
sysconfig_clock = f.read()
|
sysconfig_clock = f.read()
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
if self._allow_ioerror(err, "name"):
|
if self._allow_ioerror(err, "name"):
|
||||||
# If the config file doesn't exist detect the distribution and set regexps.
|
# If the config file doesn't exist detect the distribution and set regexps.
|
||||||
if distribution == "SuSE":
|
if distribution == "SuSE":
|
||||||
|
|
@ -427,9 +427,9 @@ class NosystemdTimezone(Timezone):
|
||||||
"""
|
"""
|
||||||
# Read the file
|
# Read the file
|
||||||
try:
|
try:
|
||||||
with open(filename, "r") as file:
|
with open(filename) as file:
|
||||||
lines = file.readlines()
|
lines = file.readlines()
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
if self._allow_ioerror(err, key):
|
if self._allow_ioerror(err, key):
|
||||||
lines = []
|
lines = []
|
||||||
else:
|
else:
|
||||||
|
|
@ -452,16 +452,16 @@ class NosystemdTimezone(Timezone):
|
||||||
try:
|
try:
|
||||||
with open(filename, "w") as file:
|
with open(filename, "w") as file:
|
||||||
file.writelines(lines)
|
file.writelines(lines)
|
||||||
except IOError:
|
except OSError:
|
||||||
self.abort(f'tried to configure {key} using a file "{filename}", but could not write to it')
|
self.abort(f'tried to configure {key} using a file "{filename}", but could not write to it')
|
||||||
self.msg.append(f"Added 1 line and deleted {len(matched_indices)} line(s) on {filename}")
|
self.msg.append(f"Added 1 line and deleted {len(matched_indices)} line(s) on {filename}")
|
||||||
|
|
||||||
def _get_value_from_config(self, key, phase):
|
def _get_value_from_config(self, key, phase):
|
||||||
filename = self.conf_files[key]
|
filename = self.conf_files[key]
|
||||||
try:
|
try:
|
||||||
with open(filename, mode="r") as file:
|
with open(filename) as file:
|
||||||
status = file.read()
|
status = file.read()
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
if self._allow_ioerror(err, key):
|
if self._allow_ioerror(err, key):
|
||||||
if key == "hwclock":
|
if key == "hwclock":
|
||||||
return "n/a"
|
return "n/a"
|
||||||
|
|
@ -602,7 +602,7 @@ class SmartOSTimezone(Timezone):
|
||||||
"""
|
"""
|
||||||
if key == "name":
|
if key == "name":
|
||||||
try:
|
try:
|
||||||
with open("/etc/default/init", "r") as f:
|
with open("/etc/default/init") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
m = re.match("^TZ=(.*)$", line.strip())
|
m = re.match("^TZ=(.*)$", line.strip())
|
||||||
if m:
|
if m:
|
||||||
|
|
@ -783,7 +783,7 @@ class AIXTimezone(Timezone):
|
||||||
def __get_timezone(self):
|
def __get_timezone(self):
|
||||||
"""Return the current value of TZ= in /etc/environment"""
|
"""Return the current value of TZ= in /etc/environment"""
|
||||||
try:
|
try:
|
||||||
with open("/etc/environment", "r") as f:
|
with open("/etc/environment") as f:
|
||||||
etcenvironment = f.read()
|
etcenvironment = f.read()
|
||||||
except Exception:
|
except Exception:
|
||||||
self.module.fail_json(msg="Issue reading contents of /etc/environment")
|
self.module.fail_json(msg="Issue reading contents of /etc/environment")
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ def wakeonlan(module, mac, broadcast, port):
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
try:
|
try:
|
||||||
sock.sendto(data, (broadcast, port))
|
sock.sendto(data, (broadcast, port))
|
||||||
except socket.error as e:
|
except OSError as e:
|
||||||
sock.close()
|
sock.close()
|
||||||
module.fail_json(msg=f"{e}", exception=traceback.format_exc())
|
module.fail_json(msg=f"{e}", exception=traceback.format_exc())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -438,7 +438,7 @@ def exec_quota(module, xfs_quota_bin, cmd, mountpoint):
|
||||||
|
|
||||||
def get_fs_by_mountpoint(mountpoint):
|
def get_fs_by_mountpoint(mountpoint):
|
||||||
mpr = None
|
mpr = None
|
||||||
with open("/proc/mounts", "r") as s:
|
with open("/proc/mounts") as s:
|
||||||
for line in s.readlines():
|
for line in s.readlines():
|
||||||
mp = line.strip().split()
|
mp = line.strip().split()
|
||||||
if len(mp) == 6 and mp[1] == mountpoint and mp[2] == "xfs":
|
if len(mp) == 6 and mp[1] == mountpoint and mp[2] == "xfs":
|
||||||
|
|
@ -450,7 +450,7 @@ def get_fs_by_mountpoint(mountpoint):
|
||||||
|
|
||||||
def get_project_id(name):
|
def get_project_id(name):
|
||||||
prjid = None
|
prjid = None
|
||||||
with open("/etc/projid", "r") as s:
|
with open("/etc/projid") as s:
|
||||||
for line in s.readlines():
|
for line in s.readlines():
|
||||||
line = line.strip().partition(":")
|
line = line.strip().partition(":")
|
||||||
if line[0] == name:
|
if line[0] == name:
|
||||||
|
|
|
||||||
|
|
@ -577,7 +577,7 @@ def repo_refresh(m):
|
||||||
|
|
||||||
|
|
||||||
def get_fs_type_and_readonly_state(mount_point):
|
def get_fs_type_and_readonly_state(mount_point):
|
||||||
with open("/proc/mounts", "r") as file:
|
with open("/proc/mounts") as file:
|
||||||
for line in file.readlines():
|
for line in file.readlines():
|
||||||
fields = line.split()
|
fields = line.split()
|
||||||
path = fields[1]
|
path = fields[1]
|
||||||
|
|
|
||||||
|
|
@ -403,7 +403,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
with open(repo, encoding="utf-8") as file:
|
with open(repo, encoding="utf-8") as file:
|
||||||
repofile_text = file.read()
|
repofile_text = file.read()
|
||||||
except IOError:
|
except OSError:
|
||||||
module.fail_json(msg="Error opening .repo file from provided path")
|
module.fail_json(msg="Error opening .repo file from provided path")
|
||||||
|
|
||||||
repofile = configparser.ConfigParser()
|
repofile = configparser.ConfigParser()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue