Commit 4dc59804 by Michael DeHaan

Merge pull request #6746 from Jmainguy/svr4pkg

svr4pkg changes - Did my best to rebase. Now includes the latest changes made to devel, al...
parents 6c6523aa bef544dd
...@@ -65,6 +65,12 @@ options: ...@@ -65,6 +65,12 @@ options:
default: "all" default: "all"
choices: ["current", "all"] choices: ["current", "all"]
version_added: "1.6" version_added: "1.6"
category:
description:
- Install/Remove category instead of a single package.
required: false
choices: ["true", "false"]
version_added: "1.6"
''' '''
EXAMPLES = ''' EXAMPLES = '''
...@@ -79,15 +85,20 @@ EXAMPLES = ''' ...@@ -79,15 +85,20 @@ EXAMPLES = '''
# Ensure that a package is not installed. # Ensure that a package is not installed.
- svr4pkg: name=SUNWgnome-sound-recorder state=absent - svr4pkg: name=SUNWgnome-sound-recorder state=absent
# Ensure that a category is not installed.
- svr4pkg: name=FIREFOX state=absent category=true
''' '''
import os import os
import tempfile import tempfile
def package_installed(module, name): def package_installed(module, name, category):
cmd = [module.get_bin_path('pkginfo', True)] cmd = [module.get_bin_path('pkginfo', True)]
cmd.append('-q') cmd.append('-q')
if category:
cmd.append('-c')
cmd.append(name) cmd.append(name)
rc, out, err = module.run_command(' '.join(cmd)) rc, out, err = module.run_command(' '.join(cmd))
if rc == 0: if rc == 0:
...@@ -124,7 +135,7 @@ def run_command(module, cmd): ...@@ -124,7 +135,7 @@ def run_command(module, cmd):
cmd[0] = module.get_bin_path(progname, True) cmd[0] = module.get_bin_path(progname, True)
return module.run_command(cmd) 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() adminfile = create_admin_file()
cmd = [ 'pkgadd', '-n'] cmd = [ 'pkgadd', '-n']
if zone == 'current': if zone == 'current':
...@@ -134,6 +145,8 @@ def package_install(module, name, src, proxy, response_file, zone): ...@@ -134,6 +145,8 @@ def package_install(module, name, src, proxy, response_file, zone):
cmd += [ '-x', proxy ] cmd += [ '-x', proxy ]
if response_file is not None: if response_file is not None:
cmd += [ '-r', response_file ] cmd += [ '-r', response_file ]
if category:
cmd += [ '-Y' ]
cmd.append(name) cmd.append(name)
(rc, out, err) = run_command(module, cmd) (rc, out, err) = run_command(module, cmd)
os.unlink(adminfile) os.unlink(adminfile)
...@@ -141,7 +154,10 @@ def package_install(module, name, src, proxy, response_file, zone): ...@@ -141,7 +154,10 @@ def package_install(module, name, src, proxy, response_file, zone):
def package_uninstall(module, name, src): def package_uninstall(module, name, src):
adminfile = create_admin_file() 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) (rc, out, err) = run_command(module, cmd)
os.unlink(adminfile) os.unlink(adminfile)
return (rc, out, err) return (rc, out, err)
...@@ -154,7 +170,8 @@ def main(): ...@@ -154,7 +170,8 @@ def main():
src = dict(default = None), src = dict(default = None),
proxy = dict(default = None), proxy = dict(default = None),
response_file = 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 supports_check_mode=True
) )
...@@ -164,6 +181,7 @@ def main(): ...@@ -164,6 +181,7 @@ def main():
proxy = module.params['proxy'] proxy = module.params['proxy']
response_file = module.params['response_file'] response_file = module.params['response_file']
zone = module.params['zone'] zone = module.params['zone']
category = module.params['category']
rc = None rc = None
out = '' out = ''
err = '' err = ''
...@@ -175,20 +193,20 @@ def main(): ...@@ -175,20 +193,20 @@ def main():
if src is None: if src is None:
module.fail_json(name=name, module.fail_json(name=name,
msg="src is required when state=present") msg="src is required when state=present")
if not package_installed(module, name): if not package_installed(module, name, category):
if module.check_mode: if module.check_mode:
module.exit_json(changed=True) 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 # Stdout is normally empty but for some packages can be
# very long and is not often useful # very long and is not often useful
if len(out) > 75: if len(out) > 75:
out = out[:75] + '...' out = out[:75] + '...'
elif state == 'absent': elif state == 'absent':
if package_installed(module, name): if package_installed(module, name, category):
if module.check_mode: if module.check_mode:
module.exit_json(changed=True) 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] out = out[:75]
if rc is None: if rc is None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment