mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
teach apt module to support --check mode
This commit is contained in:
parent
d2bf205a5d
commit
53924b4599
1 changed files with 9 additions and 2 deletions
11
library/apt
11
library/apt
|
@ -138,6 +138,9 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None, install_reco
|
|||
if not install_recommends:
|
||||
cmd += " --no-install-recommends"
|
||||
|
||||
if m.check_mode:
|
||||
m.exit_json(changed=True)
|
||||
|
||||
rc, out, err = m.run_command(cmd)
|
||||
if rc:
|
||||
m.fail_json(msg="'apt-get install %s' failed: %s" % (packages, err))
|
||||
|
@ -159,6 +162,10 @@ def remove(m, pkgspec, cache, purge=False):
|
|||
else:
|
||||
purge = '--purge' if purge else ''
|
||||
cmd = "%s -q -y %s remove %s" % (APT, purge,packages)
|
||||
|
||||
if m.check_mode:
|
||||
m.exit_json(changed=True)
|
||||
|
||||
rc, out, err = m.run_command(cmd)
|
||||
if rc:
|
||||
m.fail_json(msg="'apt-get remove %s' failed: %s" % (packages, err))
|
||||
|
@ -175,7 +182,8 @@ def main():
|
|||
default_release = dict(default=None, aliases=['default-release']),
|
||||
install_recommends = dict(default='yes', aliases=['install-recommends'], choices=['yes', 'no']),
|
||||
force = dict(default='no', choices=['yes', 'no'])
|
||||
)
|
||||
),
|
||||
supports_check_mode = True
|
||||
)
|
||||
|
||||
try:
|
||||
|
@ -230,4 +238,3 @@ def main():
|
|||
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
||||
|
||||
main()
|
||||
|
||||
|
|
Loading…
Reference in a new issue