1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-01 01:46:18 +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

@ -108,44 +108,44 @@ from ansible.module_utils.basic import AnsibleModule
def packages_not_installed(module, names):
''' Check if each package is installed and return list of the ones absent '''
"""Check if each package is installed and return list of the ones absent"""
pkgs = []
for pkg in names:
rc, out, err = run_command(module, ['pkginfo', '-q', pkg])
rc, out, err = run_command(module, ["pkginfo", "-q", pkg])
if rc != 0:
pkgs.append(pkg)
return pkgs
def packages_installed(module, names):
''' Check if each package is installed and return list of the ones present '''
"""Check if each package is installed and return list of the ones present"""
pkgs = []
for pkg in names:
if not pkg.startswith('CSW'):
if not pkg.startswith("CSW"):
continue
rc, out, err = run_command(module, ['pkginfo', '-q', pkg])
rc, out, err = run_command(module, ["pkginfo", "-q", pkg])
if rc == 0:
pkgs.append(pkg)
return pkgs
def packages_not_latest(module, names, site, update_catalog):
''' Check status of each package and return list of the ones with an upgrade available '''
cmd = ['pkgutil']
"""Check status of each package and return list of the ones with an upgrade available"""
cmd = ["pkgutil"]
if update_catalog:
cmd.append('-U')
cmd.append('-c')
cmd.append("-U")
cmd.append("-c")
if site is not None:
cmd.extend(['-t', site])
if names != ['*']:
cmd.extend(["-t", site])
if names != ["*"]:
cmd.extend(names)
rc, out, err = run_command(module, cmd)
# Find packages in the catalog which are not up to date
packages = []
for line in out.split('\n')[1:-1]:
if 'catalog' not in line and 'SAME' not in line:
packages.append(line.split(' ')[0])
for line in out.split("\n")[1:-1]:
if "catalog" not in line and "SAME" not in line:
packages.append(line.split(" ")[0])
# Remove duplicates
return list(set(packages))
@ -153,45 +153,45 @@ def packages_not_latest(module, names, site, update_catalog):
def run_command(module, cmd, **kwargs):
progname = cmd[0]
cmd[0] = module.get_bin_path(progname, True, ['/opt/csw/bin'])
cmd[0] = module.get_bin_path(progname, True, ["/opt/csw/bin"])
return module.run_command(cmd, **kwargs)
def package_install(module, state, pkgs, site, update_catalog, force):
cmd = ['pkgutil']
cmd = ["pkgutil"]
if module.check_mode:
cmd.append('-n')
cmd.append('-iy')
cmd.append("-n")
cmd.append("-iy")
if update_catalog:
cmd.append('-U')
cmd.append("-U")
if site is not None:
cmd.extend(['-t', site])
cmd.extend(["-t", site])
if force:
cmd.append('-f')
cmd.append("-f")
cmd.extend(pkgs)
return run_command(module, cmd)
def package_upgrade(module, pkgs, site, update_catalog, force):
cmd = ['pkgutil']
cmd = ["pkgutil"]
if module.check_mode:
cmd.append('-n')
cmd.append('-uy')
cmd.append("-n")
cmd.append("-uy")
if update_catalog:
cmd.append('-U')
cmd.append("-U")
if site is not None:
cmd.extend(['-t', site])
cmd.extend(["-t", site])
if force:
cmd.append('-f')
cmd.append("-f")
cmd += pkgs
return run_command(module, cmd)
def package_uninstall(module, pkgs):
cmd = ['pkgutil']
cmd = ["pkgutil"]
if module.check_mode:
cmd.append('-n')
cmd.append('-ry')
cmd.append("-n")
cmd.append("-ry")
cmd.extend(pkgs)
return run_command(module, cmd)
@ -199,31 +199,31 @@ def package_uninstall(module, pkgs):
def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(type='list', elements='str', required=True, aliases=['pkg']),
state=dict(type='str', required=True, choices=['absent', 'installed', 'latest', 'present', 'removed']),
site=dict(type='str'),
update_catalog=dict(type='bool', default=False),
force=dict(type='bool', default=False),
name=dict(type="list", elements="str", required=True, aliases=["pkg"]),
state=dict(type="str", required=True, choices=["absent", "installed", "latest", "present", "removed"]),
site=dict(type="str"),
update_catalog=dict(type="bool", default=False),
force=dict(type="bool", default=False),
),
supports_check_mode=True,
)
name = module.params['name']
state = module.params['state']
site = module.params['site']
update_catalog = module.params['update_catalog']
force = module.params['force']
name = module.params["name"]
state = module.params["state"]
site = module.params["site"]
update_catalog = module.params["update_catalog"]
force = module.params["force"]
rc = None
out = ''
err = ''
out = ""
err = ""
result = dict(
name=name,
state=state,
)
if state in ['installed', 'present']:
if state in ["installed", "present"]:
# Fail with an explicit error when trying to "install" '*'
if name == ['*']:
if name == ["*"]:
module.fail_json(msg="Can not use 'state: present' with name: '*'")
# Build list of packages that are actually not installed from the ones requested
@ -237,9 +237,9 @@ def main():
if rc != 0:
module.fail_json(msg=(err or out))
elif state in ['latest']:
elif state in ["latest"]:
# When using latest for *
if name == ['*']:
if name == ["*"]:
# Check for packages that are actually outdated
pkgs = packages_not_latest(module, name, site, update_catalog)
@ -266,7 +266,7 @@ def main():
if rc != 0:
module.fail_json(msg=(err or out))
elif state in ['absent', 'removed']:
elif state in ["absent", "removed"]:
# Build list of packages requested for removal that are actually present
pkgs = packages_installed(module, name)
@ -280,20 +280,20 @@ def main():
if rc is None:
# pkgutil was not executed because the package was already present/absent/up to date
result['changed'] = False
result["changed"] = False
elif rc == 0:
result['changed'] = True
result["changed"] = True
else:
result['changed'] = False
result['failed'] = True
result["changed"] = False
result["failed"] = True
if out:
result['stdout'] = out
result["stdout"] = out
if err:
result['stderr'] = err
result["stderr"] = err
module.exit_json(**result)
if __name__ == '__main__':
if __name__ == "__main__":
main()