2012-11-02 05:43:33 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# (c) 2012, Boyd Adamson <boyd () boydadamson.com>
|
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: svr4pkg
|
|
|
|
short_description: Manage Solaris SVR4 packages
|
|
|
|
description:
|
|
|
|
- Manages SVR4 packages on Solaris 10 and 11.
|
|
|
|
- These were the native packages on Solaris <= 10 and are available
|
|
|
|
as a legacy feature in Solaris 11.
|
|
|
|
- Note that this is a very basic packaging system. It will not enforce
|
|
|
|
dependencies on install or remove.
|
2013-03-30 20:44:34 +01:00
|
|
|
version_added: "0.9"
|
2012-11-02 05:43:33 +01:00
|
|
|
author: Boyd Adamson
|
|
|
|
options:
|
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- Package name, e.g. C(SUNWcsr)
|
|
|
|
required: true
|
|
|
|
|
|
|
|
state:
|
|
|
|
description:
|
|
|
|
- Whether to install (C(present)), or remove (C(absent)) a package.
|
2012-11-21 18:49:30 +01:00
|
|
|
- If the package is to be installed, then I(src) is required.
|
2012-11-02 05:43:33 +01:00
|
|
|
- The SVR4 package system doesn't provide an upgrade operation. You need to uninstall the old, then install the new package.
|
|
|
|
required: true
|
|
|
|
choices: ["present", "absent"]
|
|
|
|
|
|
|
|
src:
|
|
|
|
description:
|
|
|
|
- Specifies the location to install the package from. Required when C(state=present).
|
Documentation of svr4pkg module breaks 'make rpm'
Without this fix, generating documentation results in:
```
Traceback (most recent call last):
File "hacking/module_formatter.py", line 376, in <module>
main()
File "hacking/module_formatter.py", line 365, in main
text = template.render(doc)
File "/usr/lib64/python2.6/site-packages/jinja2/environment.py", line 669, in render
return self.environment.handle_exception(exc_info, True)
File "hacking/templates/man.j2", line 20, in top-level template code
{% for desc in v.description %}@{ desc | jpfunc }@{% endfor %}
File "hacking/module_formatter.py", line 94, in man_ify
t = _ITALIC.sub(r'\\fI' + r"\1" + r"\\fR", text)
TypeError: expected string or buffer
```
2012-11-09 02:19:22 +01:00
|
|
|
- "Can be any path acceptable to the C(pkgadd) command's C(-d) option. e.g.: C(somefile.pkg), C(/dir/with/pkgs), C(http:/server/mypkgs.pkg)."
|
2012-11-21 18:49:30 +01:00
|
|
|
- If using a file or directory, they must already be accessible by the host. See the M(copy) module for a way to get them there.
|
2012-11-02 05:43:33 +01:00
|
|
|
proxy:
|
|
|
|
description:
|
|
|
|
- HTTP[s] proxy to be used if C(src) is a URL.
|
2013-10-12 19:28:48 +02:00
|
|
|
response_file:
|
2013-10-10 01:56:47 +02:00
|
|
|
description:
|
|
|
|
- Specifies the location of a response file to be used if package expects input on install.
|
2013-06-14 11:53:43 +02:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
# Install a package from an already copied file
|
|
|
|
- svr4pkg: name=CSWcommon src=/tmp/cswpkgs.pkg state=present
|
|
|
|
|
|
|
|
# Install a package directly from an http site
|
|
|
|
- svr4pkg: name=CSWpkgutil src=http://get.opencsw.org/now state=present
|
2012-11-02 05:43:33 +01:00
|
|
|
|
2013-10-10 01:56:47 +02:00
|
|
|
# Install a package with a response file
|
2013-10-12 19:28:48 +02:00
|
|
|
- svr4pkg: name=CSWggrep src=/tmp/third-party.pkg response_file=/tmp/ggrep.response state=present
|
2013-10-10 01:56:47 +02:00
|
|
|
|
2013-06-14 11:53:43 +02:00
|
|
|
# Ensure that a package is not installed.
|
|
|
|
- svr4pkg: name=SUNWgnome-sound-recorder state=absent
|
2012-11-02 05:43:33 +01:00
|
|
|
'''
|
2013-06-14 11:53:43 +02:00
|
|
|
|
|
|
|
|
2012-11-02 05:43:33 +01:00
|
|
|
import os
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
def package_installed(module, name):
|
|
|
|
cmd = [module.get_bin_path('pkginfo', True)]
|
|
|
|
cmd.append('-q')
|
|
|
|
cmd.append(name)
|
2013-07-16 09:17:57 +02:00
|
|
|
rc, out, err = module.run_command(' '.join(cmd))
|
Update modules to use run_command in module_common.py
This updates apt, apt_repository, command, cron, easy_install, facter,
fireball, git, group, mount, ohai, pip, service, setup, subversion,
supervisorctl, svr4pkg, user, and yum to take advantage of run_command
in module_common.py.
2013-01-12 07:10:21 +01:00
|
|
|
if rc == 0:
|
2012-11-02 05:43:33 +01:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def create_admin_file():
|
|
|
|
(desc, filename) = tempfile.mkstemp(prefix='ansible_svr4pkg', text=True)
|
|
|
|
fullauto = '''
|
|
|
|
mail=
|
|
|
|
instance=unique
|
|
|
|
partial=nocheck
|
|
|
|
runlevel=quit
|
|
|
|
idepend=nocheck
|
|
|
|
rdepend=nocheck
|
|
|
|
space=quit
|
|
|
|
setuid=nocheck
|
|
|
|
conflict=nocheck
|
|
|
|
action=nocheck
|
|
|
|
networktimeout=60
|
|
|
|
networkretries=3
|
|
|
|
authentication=quit
|
|
|
|
keystore=/var/sadm/security
|
|
|
|
proxy=
|
|
|
|
basedir=default
|
|
|
|
'''
|
|
|
|
os.write(desc, fullauto)
|
|
|
|
os.close(desc)
|
|
|
|
return filename
|
|
|
|
|
|
|
|
def run_command(module, cmd):
|
|
|
|
progname = cmd[0]
|
|
|
|
cmd[0] = module.get_bin_path(progname, True)
|
Update modules to use run_command in module_common.py
This updates apt, apt_repository, command, cron, easy_install, facter,
fireball, git, group, mount, ohai, pip, service, setup, subversion,
supervisorctl, svr4pkg, user, and yum to take advantage of run_command
in module_common.py.
2013-01-12 07:10:21 +01:00
|
|
|
return module.run_command(cmd)
|
2012-11-02 05:43:33 +01:00
|
|
|
|
2013-10-12 19:28:48 +02:00
|
|
|
def package_install(module, name, src, proxy, response_file):
|
2012-11-02 05:43:33 +01:00
|
|
|
adminfile = create_admin_file()
|
|
|
|
cmd = [ 'pkgadd', '-na', adminfile, '-d', src ]
|
|
|
|
if proxy is not None:
|
|
|
|
cmd += [ '-x', proxy ]
|
2013-10-12 19:28:48 +02:00
|
|
|
if response_file is not None:
|
|
|
|
cmd += [ '-r', response_file ]
|
2012-11-02 05:43:33 +01:00
|
|
|
cmd.append(name)
|
|
|
|
(rc, out, err) = run_command(module, cmd)
|
|
|
|
os.unlink(adminfile)
|
|
|
|
return (rc, out, err)
|
|
|
|
|
|
|
|
def package_uninstall(module, name, src):
|
|
|
|
adminfile = create_admin_file()
|
|
|
|
cmd = [ 'pkgrm', '-na', adminfile, name]
|
|
|
|
(rc, out, err) = run_command(module, cmd)
|
|
|
|
os.unlink(adminfile)
|
|
|
|
return (rc, out, err)
|
|
|
|
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec = dict(
|
|
|
|
name = dict(required = True),
|
|
|
|
state = dict(required = True, choices=['present', 'absent']),
|
|
|
|
src = dict(default = None),
|
2013-10-10 01:56:47 +02:00
|
|
|
proxy = dict(default = None),
|
2013-10-12 19:28:48 +02:00
|
|
|
response_file = dict(default = None)
|
2013-02-27 21:23:35 +01:00
|
|
|
),
|
|
|
|
supports_check_mode=True
|
|
|
|
)
|
2012-11-02 05:43:33 +01:00
|
|
|
state = module.params['state']
|
|
|
|
name = module.params['name']
|
|
|
|
src = module.params['src']
|
|
|
|
proxy = module.params['proxy']
|
2013-10-12 19:28:48 +02:00
|
|
|
response_file = module.params['response_file']
|
2012-11-02 05:43:33 +01:00
|
|
|
rc = None
|
|
|
|
out = ''
|
|
|
|
err = ''
|
|
|
|
result = {}
|
|
|
|
result['name'] = name
|
|
|
|
result['state'] = state
|
|
|
|
|
|
|
|
if state == 'present':
|
|
|
|
if src is None:
|
|
|
|
module.fail_json(name=name,
|
|
|
|
msg="src is required when state=present")
|
|
|
|
if not package_installed(module, name):
|
2013-02-27 21:23:35 +01:00
|
|
|
if module.check_mode:
|
|
|
|
module.exit_json(changed=True)
|
2013-10-12 19:28:48 +02:00
|
|
|
(rc, out, err) = package_install(module, name, src, proxy, response_file)
|
2012-11-02 05:43:33 +01:00
|
|
|
# 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):
|
2013-02-27 21:23:35 +01:00
|
|
|
if module.check_mode:
|
|
|
|
module.exit_json(changed=True)
|
2012-11-02 05:43:33 +01:00
|
|
|
(rc, out, err) = package_uninstall(module, name, src)
|
|
|
|
out = out[:75]
|
|
|
|
|
|
|
|
if rc is None:
|
|
|
|
result['changed'] = False
|
|
|
|
else:
|
|
|
|
result['changed'] = True
|
|
|
|
|
|
|
|
if out:
|
|
|
|
result['stdout'] = out
|
|
|
|
if err:
|
|
|
|
result['stderr'] = err
|
|
|
|
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
|
|
# include magic from lib/ansible/module_common.py
|
|
|
|
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
|
|
|
main()
|