Merge pull request #6746 from Jmainguy/svr4pkg

svr4pkg changes - Did my best to rebase. Now includes the latest changes made to devel, al...
pull/6749/head
Michael DeHaan 11 years ago
commit 4dc598049e

@ -65,6 +65,12 @@ options:
default: "all"
choices: ["current", "all"]
version_added: "1.6"
category:
description:
- Install/Remove category instead of a single package.
required: false
choices: ["true", "false"]
version_added: "1.6"
'''
EXAMPLES = '''
@ -79,15 +85,20 @@ EXAMPLES = '''
# Ensure that a package is not installed.
- svr4pkg: name=SUNWgnome-sound-recorder state=absent
# Ensure that a category is not installed.
- svr4pkg: name=FIREFOX state=absent category=true
'''
import os
import tempfile
def package_installed(module, name):
def package_installed(module, name, category):
cmd = [module.get_bin_path('pkginfo', True)]
cmd.append('-q')
if category:
cmd.append('-c')
cmd.append(name)
rc, out, err = module.run_command(' '.join(cmd))
if rc == 0:
@ -124,7 +135,7 @@ def run_command(module, cmd):
cmd[0] = module.get_bin_path(progname, True)
return module.run_command(cmd)
def package_install(module, name, src, proxy, response_file, zone):
def package_install(module, name, src, proxy, response_file, zone, category):
adminfile = create_admin_file()
cmd = [ 'pkgadd', '-n']
if zone == 'current':
@ -134,6 +145,8 @@ def package_install(module, name, src, proxy, response_file, zone):
cmd += [ '-x', proxy ]
if response_file is not None:
cmd += [ '-r', response_file ]
if category:
cmd += [ '-Y' ]
cmd.append(name)
(rc, out, err) = run_command(module, cmd)
os.unlink(adminfile)
@ -141,7 +154,10 @@ def package_install(module, name, src, proxy, response_file, zone):
def package_uninstall(module, name, src):
adminfile = create_admin_file()
cmd = [ 'pkgrm', '-na', adminfile, name]
if category:
cmd = [ 'pkgrm', '-na', adminfile, '-Y', name ]
else:
cmd = [ 'pkgrm', '-na', adminfile, name]
(rc, out, err) = run_command(module, cmd)
os.unlink(adminfile)
return (rc, out, err)
@ -154,7 +170,8 @@ def main():
src = dict(default = None),
proxy = dict(default = None),
response_file = dict(default = None),
zone = dict(required=False, default = 'all', choices=['current','all'])
zone = dict(required=False, default = 'all', choices=['current','all']),
category = dict(default=False, type='bool')
),
supports_check_mode=True
)
@ -164,6 +181,7 @@ def main():
proxy = module.params['proxy']
response_file = module.params['response_file']
zone = module.params['zone']
category = module.params['category']
rc = None
out = ''
err = ''
@ -175,20 +193,20 @@ def main():
if src is None:
module.fail_json(name=name,
msg="src is required when state=present")
if not package_installed(module, name):
if not package_installed(module, name, category):
if module.check_mode:
module.exit_json(changed=True)
(rc, out, err) = package_install(module, name, src, proxy, response_file, zone)
(rc, out, err) = package_install(module, name, src, proxy, response_file, zone, category)
# Stdout is normally empty but for some packages can be
# very long and is not often useful
if len(out) > 75:
out = out[:75] + '...'
elif state == 'absent':
if package_installed(module, name):
if package_installed(module, name, category):
if module.check_mode:
module.exit_json(changed=True)
(rc, out, err) = package_uninstall(module, name, src)
(rc, out, err) = package_uninstall(module, name, src, category)
out = out[:75]
if rc is None:

Loading…
Cancel
Save