1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Support check mode with pacman module

This commit is contained in:
Mark Harrison 2013-08-17 17:44:41 -04:00
parent 5847720746
commit 0419fb74bb

View file

@ -151,6 +151,21 @@ def install_packages(module, packages):
module.exit_json(changed=False, msg="package(s) already installed")
def check_packages(module, packages, state):
would_be_changed = []
for package in packages:
installed = query_package(module, package)
if ((state == "installed" and not installed) or
(state == "absent" and installed)):
would_be_changed.append(package)
if would_be_changed:
if state == "absent":
state = "removed"
module.exit_json(changed=True, msg="%s package(s) would be %s" % (
len(would_be_changed), state))
else:
module.exit_json(change=False, msg="package(s) already %s" % state)
def main():
module = AnsibleModule(
@ -158,7 +173,8 @@ def main():
state = dict(default="installed", choices=["installed","absent"]),
update_cache = dict(default="no", aliases=["update-cache"], type='bool'),
recurse = dict(default="no", type='bool'),
name = dict(aliases=["pkg"], required=True)))
name = dict(aliases=["pkg"], required=True)),
supports_check_mode = True)
if not os.path.exists(PACMAN_PATH):
@ -166,13 +182,15 @@ def main():
p = module.params
if p["update_cache"]:
if p["update_cache"] and not module.check_mode:
update_package_db(module)
pkgs = p["name"].split(",")
if p["state"] == "installed":
if module.check_mode:
check_packages(module, pkgs, p['state'])
elif p["state"] == "installed":
install_packages(module, pkgs)
elif p["state"] == "absent":