1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-05-04 01:13:00 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -68,14 +68,15 @@ from ansible.module_utils.basic import AnsibleModule
def compare_package(version1, version2):
""" Compare version packages.
Return values:
-1 first minor
0 equal
1 first greater """
"""Compare version packages.
Return values:
-1 first minor
0 equal
1 first greater"""
def normalize(v):
return [int(x) for x in re.sub(r'(\.0+)*$', '', v).split(".")]
return [int(x) for x in re.sub(r"(\.0+)*$", "", v).split(".")]
normalized_version1 = normalize(version1)
normalized_version2 = normalize(version2)
if normalized_version1 == normalized_version2:
@ -88,15 +89,15 @@ def compare_package(version1, version2):
def query_package(module, name, depot=None):
""" Returns whether a package is installed or not and version. """
"""Returns whether a package is installed or not and version."""
cmd_list = ['/usr/sbin/swlist', '-a', 'revision', '-l', 'product']
cmd_list = ["/usr/sbin/swlist", "-a", "revision", "-l", "product"]
if depot:
cmd_list.extend(['-s', depot])
cmd_list.extend(["-s", depot])
cmd_list.append(name)
rc, stdout, stderr = module.run_command(cmd_list)
if rc == 0:
stdout = ''.join(line for line in stdout.splitlines(True) if name in line)
stdout = "".join(line for line in stdout.splitlines(True) if name in line)
version = re.sub(r"\s\s+|\t", " ", stdout).strip().split()[1]
else:
version = None
@ -105,9 +106,9 @@ def query_package(module, name, depot=None):
def remove_package(module, name):
""" Uninstall package if installed. """
"""Uninstall package if installed."""
cmd_remove = '/usr/sbin/swremove'
cmd_remove = "/usr/sbin/swremove"
rc, stdout, stderr = module.run_command([cmd_remove, name])
if rc == 0:
@ -117,9 +118,9 @@ def remove_package(module, name):
def install_package(module, depot, name):
""" Install package if not already installed """
"""Install package if not already installed"""
cmd_install = ['/usr/sbin/swinstall', '-x', 'mount_all_filesystems=false']
cmd_install = ["/usr/sbin/swinstall", "-x", "mount_all_filesystems=false"]
rc, stdout, stderr = module.run_command(cmd_install + ["-s", depot, name])
if rc == 0:
return rc, stdout
@ -130,20 +131,20 @@ def install_package(module, depot, name):
def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(aliases=['pkg'], required=True),
state=dict(choices=['present', 'absent', 'latest'], required=True),
depot=dict()
name=dict(aliases=["pkg"], required=True),
state=dict(choices=["present", "absent", "latest"], required=True),
depot=dict(),
),
supports_check_mode=True
supports_check_mode=True,
)
name = module.params['name']
state = module.params['state']
depot = module.params['depot']
name = module.params["name"]
state = module.params["state"]
depot = module.params["depot"]
changed = False
msg = "No changed"
rc = 0
if (state == 'present' or state == 'latest') and depot is None:
if (state == "present" or state == "latest") and depot is None:
output = "depot parameter is mandatory in present or latest task"
module.fail_json(name=name, msg=output, rc=rc)
@ -156,7 +157,7 @@ def main():
else:
installed = False
if (state == 'present' or state == 'latest') and installed is False:
if (state == "present" or state == "latest") and installed is False:
if module.check_mode:
module.exit_json(changed=True)
rc, output = install_package(module, depot, name)
@ -168,7 +169,7 @@ def main():
else:
module.fail_json(name=name, msg=output, rc=rc)
elif state == 'latest' and installed is True:
elif state == "latest" and installed is True:
# Check depot version
rc, version_depot = query_package(module, name, depot)
@ -190,7 +191,7 @@ def main():
output = f"Software package not in repository {depot}"
module.fail_json(name=name, msg=output, rc=rc)
elif state == 'absent' and installed is True:
elif state == "absent" and installed is True:
if module.check_mode:
module.exit_json(changed=True)
rc, output = remove_package(module, name)
@ -206,5 +207,5 @@ def main():
module.exit_json(changed=changed, name=name, state=state, msg=msg)
if __name__ == '__main__':
if __name__ == "__main__":
main()