mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-25 05:02:46 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -109,7 +109,6 @@ def query_package_provides(module, name, root):
|
|||
|
||||
|
||||
def update_package_db(module):
|
||||
|
||||
urpmiupdate_path = module.get_bin_path("urpmi.update", True)
|
||||
cmd = [urpmiupdate_path, "-a", "-q"]
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
|
|
@ -118,7 +117,6 @@ def update_package_db(module):
|
|||
|
||||
|
||||
def remove_packages(module, packages, root):
|
||||
|
||||
remove_c = 0
|
||||
# Using a for loop in case of error, we can report the package that failed
|
||||
for package in packages:
|
||||
|
|
@ -136,14 +134,12 @@ def remove_packages(module, packages, root):
|
|||
remove_c += 1
|
||||
|
||||
if remove_c > 0:
|
||||
|
||||
module.exit_json(changed=True, msg=f"removed {remove_c} package(s)")
|
||||
|
||||
module.exit_json(changed=False, msg="package(s) already absent")
|
||||
|
||||
|
||||
def install_packages(module, pkgspec, root, force=True, no_recommends=True):
|
||||
|
||||
packages = ""
|
||||
for package in pkgspec:
|
||||
if not query_package_provides(module, package, root):
|
||||
|
|
@ -151,12 +147,12 @@ def install_packages(module, pkgspec, root, force=True, no_recommends=True):
|
|||
|
||||
if len(packages) != 0:
|
||||
if no_recommends:
|
||||
no_recommends_yes = ['--no-recommends']
|
||||
no_recommends_yes = ["--no-recommends"]
|
||||
else:
|
||||
no_recommends_yes = []
|
||||
|
||||
if force:
|
||||
force_yes = ['--force']
|
||||
force_yes = ["--force"]
|
||||
else:
|
||||
force_yes = []
|
||||
|
||||
|
|
@ -188,27 +184,26 @@ def root_option(root):
|
|||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
state=dict(type='str', default='present',
|
||||
choices=['absent', 'installed', 'present', 'removed']),
|
||||
update_cache=dict(type='bool', default=False),
|
||||
force=dict(type='bool', default=True),
|
||||
no_recommends=dict(type='bool', default=True),
|
||||
name=dict(type='list', elements='str', required=True, aliases=['package', 'pkg']),
|
||||
root=dict(type='str', aliases=['installroot']),
|
||||
state=dict(type="str", default="present", choices=["absent", "installed", "present", "removed"]),
|
||||
update_cache=dict(type="bool", default=False),
|
||||
force=dict(type="bool", default=True),
|
||||
no_recommends=dict(type="bool", default=True),
|
||||
name=dict(type="list", elements="str", required=True, aliases=["package", "pkg"]),
|
||||
root=dict(type="str", aliases=["installroot"]),
|
||||
),
|
||||
)
|
||||
|
||||
p = module.params
|
||||
|
||||
if p['update_cache']:
|
||||
if p["update_cache"]:
|
||||
update_package_db(module)
|
||||
|
||||
if p['state'] in ['installed', 'present']:
|
||||
install_packages(module, p['name'], p['root'], p['force'], p['no_recommends'])
|
||||
if p["state"] in ["installed", "present"]:
|
||||
install_packages(module, p["name"], p["root"], p["force"], p["no_recommends"])
|
||||
|
||||
elif p['state'] in ['removed', 'absent']:
|
||||
remove_packages(module, p['name'], p['root'])
|
||||
elif p["state"] in ["removed", "absent"]:
|
||||
remove_packages(module, p["name"], p["root"])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue