mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
add check mode support
Could it be that easy or do I have missed something?
This commit is contained in:
parent
70a9a797fa
commit
e504ff94e6
1 changed files with 13 additions and 10 deletions
|
@ -89,9 +89,10 @@ def remove_packages(module, pkgin_path, packages):
|
||||||
if not query_package(module, pkgin_path, package):
|
if not query_package(module, pkgin_path, package):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if not module.check_mode:
|
||||||
rc, out, err = module.run_command("%s delete -y %s" % (pkgin_path, package))
|
rc, out, err = module.run_command("%s delete -y %s" % (pkgin_path, package))
|
||||||
|
|
||||||
if query_package(module, pkgin_path, package):
|
if not module.check_mode and query_package(module, pkgin_path, package):
|
||||||
module.fail_json(msg="failed to remove %s: %s" % (package, out))
|
module.fail_json(msg="failed to remove %s: %s" % (package, out))
|
||||||
|
|
||||||
remove_c += 1
|
remove_c += 1
|
||||||
|
@ -110,7 +111,7 @@ def install_packages(module, pkgin_path, packages, cached, pkgsite):
|
||||||
if pkgsite != "":
|
if pkgsite != "":
|
||||||
pkgsite="PACKAGESITE=%s" % (pkgsite)
|
pkgsite="PACKAGESITE=%s" % (pkgsite)
|
||||||
|
|
||||||
if cached == "no":
|
if not module.check_mode and cached == "no":
|
||||||
rc, out, err = module.run_command("%s %s update" % (pkgsite, pkgin_path))
|
rc, out, err = module.run_command("%s %s update" % (pkgsite, pkgin_path))
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
module.fail_json(msg="Could not update catalogue")
|
module.fail_json(msg="Could not update catalogue")
|
||||||
|
@ -119,9 +120,10 @@ def install_packages(module, pkgin_path, packages, cached, pkgsite):
|
||||||
if query_package(module, pkgin_path, package):
|
if query_package(module, pkgin_path, package):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if not module.check_mode:
|
||||||
rc, out, err = module.run_command("%s %s install -U -y %s" % (pkgsite, pkgin_path, package))
|
rc, out, err = module.run_command("%s %s install -U -y %s" % (pkgsite, pkgin_path, package))
|
||||||
|
|
||||||
if not query_package(module, pkgin_path, package):
|
if not module.check_mode and query_package(module, pkgin_path, package):
|
||||||
module.fail_json(msg="failed to install %s: %s" % (package, out))
|
module.fail_json(msg="failed to install %s: %s" % (package, out))
|
||||||
|
|
||||||
install_c += 1
|
install_c += 1
|
||||||
|
@ -137,8 +139,9 @@ def main():
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
state = dict(default="present", choices=["present","absent"]),
|
state = dict(default="present", choices=["present","absent"]),
|
||||||
name = dict(aliases=["pkg"], required=True),
|
name = dict(aliases=["pkg"], required=True),
|
||||||
cached = dict(default="no", required=False, choices=["yes","no"]),
|
cached = dict(default="supports_check_modeno", required=False, choices=["yes","no"]),
|
||||||
pkgsite = dict(default="", required=False)))
|
pkgsite = dict(default="", required=False))
|
||||||
|
supports_check_mode = True)
|
||||||
|
|
||||||
pkgin_path = module.get_bin_path('pkg', True)
|
pkgin_path = module.get_bin_path('pkg', True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue