mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Bulk autopep8 (modules)
As agreed in 2017-12-07 Core meeting bulk fix pep8 issues Generated using: autopep8 1.3.3 (pycodestyle: 2.3.1) autopep8 -r --max-line-length 160 --in-place --ignore E305,E402,E722,E741 lib/ansible/modules Manually fix issues that autopep8 has introduced
This commit is contained in:
committed by
John R Barker
parent
d13d7e9404
commit
c57a7f05e1
@@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION='''
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: bundler
|
||||
short_description: Manage Ruby Gem dependencies with Bundler
|
||||
@@ -104,7 +104,7 @@ options:
|
||||
author: "Tim Hoiberg (@thoiberg)"
|
||||
'''
|
||||
|
||||
EXAMPLES='''
|
||||
EXAMPLES = '''
|
||||
# Installs gems from a Gemfile in the current directory
|
||||
- bundler:
|
||||
state: present
|
||||
@@ -159,7 +159,7 @@ def main():
|
||||
extra_args=dict(default=None, required=False),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
)
|
||||
|
||||
state = module.params.get('state')
|
||||
chdir = module.params.get('chdir')
|
||||
|
||||
@@ -141,6 +141,7 @@ def _is_package_installed(module, name, locallib, cpanm, version):
|
||||
res, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
return res == 0
|
||||
|
||||
|
||||
def _build_cmd_line(name, from_path, notest, locallib, mirror, mirror_only, installdeps, cpanm, use_sudo):
|
||||
# this code should use "%s" like everything else and just return early but not fixing all of it now.
|
||||
# don't copy stuff like this
|
||||
@@ -197,23 +198,23 @@ def main():
|
||||
required_one_of=[['name', 'from_path']],
|
||||
)
|
||||
|
||||
cpanm = _get_cpanm_path(module)
|
||||
name = module.params['name']
|
||||
from_path = module.params['from_path']
|
||||
notest = module.boolean(module.params.get('notest', False))
|
||||
locallib = module.params['locallib']
|
||||
mirror = module.params['mirror']
|
||||
cpanm = _get_cpanm_path(module)
|
||||
name = module.params['name']
|
||||
from_path = module.params['from_path']
|
||||
notest = module.boolean(module.params.get('notest', False))
|
||||
locallib = module.params['locallib']
|
||||
mirror = module.params['mirror']
|
||||
mirror_only = module.params['mirror_only']
|
||||
installdeps = module.params['installdeps']
|
||||
use_sudo = module.params['system_lib']
|
||||
version = module.params['version']
|
||||
use_sudo = module.params['system_lib']
|
||||
version = module.params['version']
|
||||
|
||||
changed = False
|
||||
changed = False
|
||||
|
||||
installed = _is_package_installed(module, name, locallib, cpanm, version)
|
||||
|
||||
if not installed:
|
||||
cmd = _build_cmd_line(name, from_path, notest, locallib, mirror, mirror_only, installdeps, cpanm, use_sudo)
|
||||
cmd = _build_cmd_line(name, from_path, notest, locallib, mirror, mirror_only, installdeps, cpanm, use_sudo)
|
||||
|
||||
rc_cpanm, out_cpanm, err_cpanm = module.run_command(cmd, check_rc=False)
|
||||
|
||||
|
||||
@@ -121,8 +121,9 @@ def get_rubygems_path(module):
|
||||
result = [module.get_bin_path('gem', True)]
|
||||
return result
|
||||
|
||||
|
||||
def get_rubygems_version(module):
|
||||
cmd = get_rubygems_path(module) + [ '--version' ]
|
||||
cmd = get_rubygems_path(module) + ['--version']
|
||||
(rc, out, err) = module.run_command(cmd, check_rc=True)
|
||||
|
||||
match = re.match(r'^(\d+)\.(\d+)\.(\d+)', out)
|
||||
@@ -131,6 +132,7 @@ def get_rubygems_version(module):
|
||||
|
||||
return tuple(int(x) for x in match.groups())
|
||||
|
||||
|
||||
def get_installed_versions(module, remote=False):
|
||||
|
||||
cmd = get_rubygems_path(module)
|
||||
@@ -138,7 +140,7 @@ def get_installed_versions(module, remote=False):
|
||||
if remote:
|
||||
cmd.append('--remote')
|
||||
if module.params['repository']:
|
||||
cmd.extend([ '--source', module.params['repository'] ])
|
||||
cmd.extend(['--source', module.params['repository']])
|
||||
cmd.append('-n')
|
||||
cmd.append('^%s$' % module.params['name'])
|
||||
(rc, out, err) = module.run_command(cmd, check_rc=True)
|
||||
@@ -151,6 +153,7 @@ def get_installed_versions(module, remote=False):
|
||||
installed_versions.append(version.split()[0])
|
||||
return installed_versions
|
||||
|
||||
|
||||
def exists(module):
|
||||
|
||||
if module.params['state'] == 'latest':
|
||||
@@ -166,6 +169,7 @@ def exists(module):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def uninstall(module):
|
||||
|
||||
if module.check_mode:
|
||||
@@ -173,13 +177,14 @@ def uninstall(module):
|
||||
cmd = get_rubygems_path(module)
|
||||
cmd.append('uninstall')
|
||||
if module.params['version']:
|
||||
cmd.extend([ '--version', module.params['version'] ])
|
||||
cmd.extend(['--version', module.params['version']])
|
||||
else:
|
||||
cmd.append('--all')
|
||||
cmd.append('--executable')
|
||||
cmd.append(module.params['name'])
|
||||
module.run_command(cmd, check_rc=True)
|
||||
|
||||
|
||||
def install(module):
|
||||
|
||||
if module.check_mode:
|
||||
@@ -194,9 +199,9 @@ def install(module):
|
||||
cmd = get_rubygems_path(module)
|
||||
cmd.append('install')
|
||||
if module.params['version']:
|
||||
cmd.extend([ '--version', module.params['version'] ])
|
||||
cmd.extend(['--version', module.params['version']])
|
||||
if module.params['repository']:
|
||||
cmd.extend([ '--source', module.params['repository'] ])
|
||||
cmd.extend(['--source', module.params['repository']])
|
||||
if not module.params['include_dependencies']:
|
||||
cmd.append('--ignore-dependencies')
|
||||
else:
|
||||
@@ -218,28 +223,29 @@ def install(module):
|
||||
cmd.append('--env-shebang')
|
||||
cmd.append(module.params['gem_source'])
|
||||
if module.params['build_flags']:
|
||||
cmd.extend([ '--', module.params['build_flags'] ])
|
||||
cmd.extend(['--', module.params['build_flags']])
|
||||
module.run_command(cmd, check_rc=True)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
executable = dict(required=False, type='path'),
|
||||
gem_source = dict(required=False, type='path'),
|
||||
include_dependencies = dict(required=False, default=True, type='bool'),
|
||||
name = dict(required=True, type='str'),
|
||||
repository = dict(required=False, aliases=['source'], type='str'),
|
||||
state = dict(required=False, default='present', choices=['present','absent','latest'], type='str'),
|
||||
user_install = dict(required=False, default=True, type='bool'),
|
||||
pre_release = dict(required=False, default=False, type='bool'),
|
||||
include_doc = dict(required=False, default=False, type='bool'),
|
||||
env_shebang = dict(required=False, default=False, type='bool'),
|
||||
version = dict(required=False, type='str'),
|
||||
build_flags = dict(required=False, type='str'),
|
||||
argument_spec=dict(
|
||||
executable=dict(required=False, type='path'),
|
||||
gem_source=dict(required=False, type='path'),
|
||||
include_dependencies=dict(required=False, default=True, type='bool'),
|
||||
name=dict(required=True, type='str'),
|
||||
repository=dict(required=False, aliases=['source'], type='str'),
|
||||
state=dict(required=False, default='present', choices=['present', 'absent', 'latest'], type='str'),
|
||||
user_install=dict(required=False, default=True, type='bool'),
|
||||
pre_release=dict(required=False, default=False, type='bool'),
|
||||
include_doc=dict(required=False, default=False, type='bool'),
|
||||
env_shebang=dict(required=False, default=False, type='bool'),
|
||||
version=dict(required=False, type='str'),
|
||||
build_flags=dict(required=False, type='str'),
|
||||
),
|
||||
supports_check_mode = True,
|
||||
mutually_exclusive = [ ['gem_source','repository'], ['gem_source','version'] ],
|
||||
supports_check_mode=True,
|
||||
mutually_exclusive=[['gem_source', 'repository'], ['gem_source', 'version']],
|
||||
)
|
||||
|
||||
if module.params['version'] and module.params['state'] == 'latest':
|
||||
@@ -252,7 +258,7 @@ def main():
|
||||
|
||||
changed = False
|
||||
|
||||
if module.params['state'] in [ 'present', 'latest']:
|
||||
if module.params['state'] in ['present', 'latest']:
|
||||
if not exists(module):
|
||||
install(module)
|
||||
changed = True
|
||||
|
||||
@@ -315,12 +315,12 @@ class MavenDownloader:
|
||||
def _request(self, url, failmsg, f):
|
||||
url_to_use = url
|
||||
parsed_url = urlparse(url)
|
||||
if parsed_url.scheme=='s3':
|
||||
if parsed_url.scheme == 's3':
|
||||
parsed_url = urlparse(url)
|
||||
bucket_name = parsed_url.netloc
|
||||
key_name = parsed_url.path[1:]
|
||||
client = boto3.client('s3',aws_access_key_id=self.module.params.get('username', ''), aws_secret_access_key=self.module.params.get('password', ''))
|
||||
url_to_use = client.generate_presigned_url('get_object',Params={'Bucket':bucket_name,'Key':key_name},ExpiresIn=10)
|
||||
client = boto3.client('s3', aws_access_key_id=self.module.params.get('username', ''), aws_secret_access_key=self.module.params.get('password', ''))
|
||||
url_to_use = client.generate_presigned_url('get_object', Params={'Bucket': bucket_name, 'Key': key_name}, ExpiresIn=10)
|
||||
|
||||
req_timeout = self.module.params.get('timeout')
|
||||
|
||||
@@ -335,7 +335,6 @@ class MavenDownloader:
|
||||
else:
|
||||
return f(response)
|
||||
|
||||
|
||||
def download(self, artifact, filename=None):
|
||||
filename = artifact.get_filename(filename)
|
||||
if not artifact.version or artifact.version == "latest":
|
||||
@@ -402,20 +401,20 @@ class MavenDownloader:
|
||||
def main():
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
group_id = dict(default=None),
|
||||
artifact_id = dict(default=None),
|
||||
version = dict(default="latest"),
|
||||
classifier = dict(default=''),
|
||||
extension = dict(default='jar'),
|
||||
repository_url = dict(default=None),
|
||||
username = dict(default=None,aliases=['aws_secret_key']),
|
||||
password = dict(default=None, no_log=True,aliases=['aws_secret_access_key']),
|
||||
state = dict(default="present", choices=["present","absent"]), # TODO - Implement a "latest" state
|
||||
timeout = dict(default=10, type='int'),
|
||||
dest = dict(type="path", default=None),
|
||||
validate_certs = dict(required=False, default=True, type='bool'),
|
||||
keep_name = dict(required=False, default=False, type='bool'),
|
||||
argument_spec=dict(
|
||||
group_id=dict(default=None),
|
||||
artifact_id=dict(default=None),
|
||||
version=dict(default="latest"),
|
||||
classifier=dict(default=''),
|
||||
extension=dict(default='jar'),
|
||||
repository_url=dict(default=None),
|
||||
username=dict(default=None, aliases=['aws_secret_key']),
|
||||
password=dict(default=None, no_log=True, aliases=['aws_secret_access_key']),
|
||||
state=dict(default="present", choices=["present", "absent"]), # TODO - Implement a "latest" state
|
||||
timeout=dict(default=10, type='int'),
|
||||
dest=dict(type="path", default=None),
|
||||
validate_certs=dict(required=False, default=True, type='bool'),
|
||||
keep_name=dict(required=False, default=False, type='bool'),
|
||||
),
|
||||
add_file_common_args=True
|
||||
)
|
||||
@@ -429,7 +428,7 @@ def main():
|
||||
except AttributeError as e:
|
||||
module.fail_json(msg='url parsing went wrong %s' % e)
|
||||
|
||||
if parsed_url.scheme=='s3' and not HAS_BOTO:
|
||||
if parsed_url.scheme == 's3' and not HAS_BOTO:
|
||||
module.fail_json(msg='boto3 required for this module, when using s3:// repository URLs')
|
||||
|
||||
group_id = module.params["group_id"]
|
||||
|
||||
@@ -83,6 +83,7 @@ def get_local_version(pear_output):
|
||||
return installed
|
||||
return None
|
||||
|
||||
|
||||
def _get_pear_path(module):
|
||||
if module.params['executable'] and os.path.isfile(module.params['executable']):
|
||||
result = module.params['executable']
|
||||
@@ -90,6 +91,7 @@ def _get_pear_path(module):
|
||||
result = module.get_bin_path('pear', True, [module.params['executable']])
|
||||
return result
|
||||
|
||||
|
||||
def get_repository_version(pear_output):
|
||||
"""Take pear remote-info output and get the latest version"""
|
||||
lines = pear_output.split('\n')
|
||||
@@ -98,6 +100,7 @@ def get_repository_version(pear_output):
|
||||
return line.rsplit(None, 1)[-1].strip()
|
||||
return None
|
||||
|
||||
|
||||
def query_package(module, name, state="present"):
|
||||
"""Query the package status in both the local system and the repository.
|
||||
Returns a boolean to indicate if the package is installed,
|
||||
@@ -198,18 +201,14 @@ def check_packages(module, packages, state):
|
||||
module.exit_json(change=False, msg="package(s) already %s" % state)
|
||||
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
name = dict(aliases=['pkg']),
|
||||
state = dict(default='present', choices=['present', 'installed', "latest", 'absent', 'removed']),
|
||||
executable = dict(default=None, required=False, type='path')),
|
||||
required_one_of = [['name']],
|
||||
supports_check_mode = True)
|
||||
|
||||
|
||||
argument_spec=dict(
|
||||
name=dict(aliases=['pkg']),
|
||||
state=dict(default='present', choices=['present', 'installed', "latest", 'absent', 'removed']),
|
||||
executable=dict(default=None, required=False, type='path')),
|
||||
required_one_of=[['name']],
|
||||
supports_check_mode=True)
|
||||
|
||||
p = module.params
|
||||
|
||||
|
||||
@@ -147,6 +147,7 @@ import re
|
||||
# Import module snippets.
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def parse_for_packages(stdout):
|
||||
packages = []
|
||||
data = stdout.split('\n')
|
||||
@@ -157,6 +158,7 @@ def parse_for_packages(stdout):
|
||||
packages.append(p.group(1))
|
||||
return packages
|
||||
|
||||
|
||||
def update_package_db(module, exit):
|
||||
cmd = "%s update" % (APK_PATH)
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
@@ -167,6 +169,7 @@ def update_package_db(module, exit):
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def query_package(module, name):
|
||||
cmd = "%s -v info --installed %s" % (APK_PATH, name)
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
@@ -175,6 +178,7 @@ def query_package(module, name):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def query_latest(module, name):
|
||||
cmd = "%s version %s" % (APK_PATH, name)
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
@@ -184,6 +188,7 @@ def query_latest(module, name):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def query_virtual(module, name):
|
||||
cmd = "%s -v info --description %s" % (APK_PATH, name)
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
@@ -192,6 +197,7 @@ def query_virtual(module, name):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_dependencies(module, name):
|
||||
cmd = "%s -v info --depends %s" % (APK_PATH, name)
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
@@ -201,6 +207,7 @@ def get_dependencies(module, name):
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
def upgrade_packages(module, available):
|
||||
if module.check_mode:
|
||||
cmd = "%s upgrade --simulate" % (APK_PATH)
|
||||
@@ -216,6 +223,7 @@ def upgrade_packages(module, available):
|
||||
module.exit_json(changed=False, msg="packages already upgraded", stdout=stdout, stderr=stderr, packages=packagelist)
|
||||
module.exit_json(changed=True, msg="upgraded packages", stdout=stdout, stderr=stderr, packages=packagelist)
|
||||
|
||||
|
||||
def install_packages(module, names, state):
|
||||
upgrade = False
|
||||
to_install = []
|
||||
@@ -254,6 +262,7 @@ def install_packages(module, names, state):
|
||||
module.fail_json(msg="failed to install %s" % (packages), stdout=stdout, stderr=stderr, packages=packagelist)
|
||||
module.exit_json(changed=True, msg="installed %s package(s)" % (packages), stdout=stdout, stderr=stderr, packages=packagelist)
|
||||
|
||||
|
||||
def remove_packages(module, names):
|
||||
installed = []
|
||||
for name in names:
|
||||
@@ -275,6 +284,7 @@ def remove_packages(module, names):
|
||||
# ==========================================
|
||||
# Main control flow.
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
|
||||
@@ -41,6 +41,7 @@ EXAMPLES = '''
|
||||
selection: hold
|
||||
'''
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
|
||||
@@ -181,9 +181,9 @@ class Homebrew(object):
|
||||
@ # at-sign
|
||||
'''
|
||||
|
||||
INVALID_PATH_REGEX = _create_regex_group(VALID_PATH_CHARS)
|
||||
INVALID_BREW_PATH_REGEX = _create_regex_group(VALID_BREW_PATH_CHARS)
|
||||
INVALID_PACKAGE_REGEX = _create_regex_group(VALID_PACKAGE_CHARS)
|
||||
INVALID_PATH_REGEX = _create_regex_group(VALID_PATH_CHARS)
|
||||
INVALID_BREW_PATH_REGEX = _create_regex_group(VALID_BREW_PATH_CHARS)
|
||||
INVALID_PACKAGE_REGEX = _create_regex_group(VALID_PACKAGE_CHARS)
|
||||
# /class regexes ----------------------------------------------- }}}
|
||||
|
||||
# class validations -------------------------------------------- {{{
|
||||
|
||||
@@ -137,9 +137,9 @@ class HomebrewCask(object):
|
||||
- # dashes
|
||||
'''
|
||||
|
||||
INVALID_PATH_REGEX = _create_regex_group(VALID_PATH_CHARS)
|
||||
INVALID_BREW_PATH_REGEX = _create_regex_group(VALID_BREW_PATH_CHARS)
|
||||
INVALID_CASK_REGEX = _create_regex_group(VALID_CASK_CHARS)
|
||||
INVALID_PATH_REGEX = _create_regex_group(VALID_PATH_CHARS)
|
||||
INVALID_BREW_PATH_REGEX = _create_regex_group(VALID_BREW_PATH_CHARS)
|
||||
INVALID_CASK_REGEX = _create_regex_group(VALID_CASK_CHARS)
|
||||
# /class regexes ----------------------------------------------- }}}
|
||||
|
||||
# class validations -------------------------------------------- {{{
|
||||
@@ -589,7 +589,7 @@ def main():
|
||||
for install_option in p['install_options']]
|
||||
|
||||
brew_cask = HomebrewCask(module=module, path=path, casks=casks,
|
||||
state=state, update_homebrew=update_homebrew,
|
||||
state=state, update_homebrew=update_homebrew,
|
||||
install_options=install_options)
|
||||
(failed, changed, message) = brew_cask.run()
|
||||
if failed:
|
||||
|
||||
@@ -158,8 +158,8 @@ def install_overlay(module, name, list_url=None):
|
||||
|
||||
if not layman.is_repo(name):
|
||||
if not list_url:
|
||||
raise ModuleError("Overlay '%s' is not on the list of known " \
|
||||
"overlays and URL of the remote list was not provided." % name)
|
||||
raise ModuleError("Overlay '%s' is not on the list of known "
|
||||
"overlays and URL of the remote list was not provided." % name)
|
||||
|
||||
overlay_defs = layman_conf.get_option('overlay_defs')
|
||||
dest = path.join(overlay_defs, name + '.xml')
|
||||
@@ -209,7 +209,7 @@ def sync_overlay(name):
|
||||
layman = init_layman()
|
||||
|
||||
if not layman.sync(name):
|
||||
messages = [ str(item[1]) for item in layman.sync_results[2] ]
|
||||
messages = [str(item[1]) for item in layman.sync_results[2]]
|
||||
raise ModuleError(messages)
|
||||
|
||||
|
||||
@@ -227,11 +227,11 @@ def sync_overlays():
|
||||
def main():
|
||||
# define module
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
name = dict(required=True),
|
||||
list_url = dict(aliases=['url']),
|
||||
state = dict(default="present", choices=['present', 'absent', 'updated']),
|
||||
validate_certs = dict(required=False, default=True, type='bool'),
|
||||
argument_spec=dict(
|
||||
name=dict(required=True),
|
||||
list_url=dict(aliases=['url']),
|
||||
state=dict(default="present", choices=['present', 'absent', 'updated']),
|
||||
validate_certs=dict(required=False, default=True, type='bool'),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
@@ -68,6 +68,7 @@ EXAMPLES = '''
|
||||
|
||||
import pipes
|
||||
|
||||
|
||||
def update_package_db(module, port_path):
|
||||
""" Updates packages list. """
|
||||
|
||||
@@ -196,10 +197,10 @@ def deactivate_packages(module, port_path, packages):
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
name = dict(aliases=["pkg"], required=True),
|
||||
state = dict(default="present", choices=["present", "installed", "absent", "removed", "active", "inactive"]),
|
||||
update_cache = dict(default="no", aliases=["update-cache"], type='bool')
|
||||
argument_spec=dict(
|
||||
name=dict(aliases=["pkg"], required=True),
|
||||
state=dict(default="present", choices=["present", "installed", "absent", "removed", "active", "inactive"]),
|
||||
update_cache=dict(default="no", aliases=["update-cache"], type='bool')
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ EXAMPLES = '''
|
||||
|
||||
import pipes
|
||||
|
||||
|
||||
def update_package_db(module, opkg_path):
|
||||
""" Updates packages list. """
|
||||
|
||||
|
||||
@@ -132,6 +132,7 @@ EXAMPLES = '''
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def query_package(module, name):
|
||||
"""Search for the package by name.
|
||||
|
||||
@@ -201,8 +202,8 @@ def query_package(module, name):
|
||||
|
||||
|
||||
def format_action_message(module, action, count):
|
||||
vars = { "actioned": action,
|
||||
"count": count }
|
||||
vars = {"actioned": action,
|
||||
"count": count}
|
||||
|
||||
if module.check_mode:
|
||||
message = "would have %(actioned)s %(count)d package" % vars
|
||||
@@ -227,10 +228,10 @@ def format_pkgin_command(module, command, package=None):
|
||||
else:
|
||||
force = ""
|
||||
|
||||
vars = { "pkgin": PKGIN_PATH,
|
||||
"command": command,
|
||||
"package": package,
|
||||
"force": force}
|
||||
vars = {"pkgin": PKGIN_PATH,
|
||||
"command": command,
|
||||
"package": package,
|
||||
"force": force}
|
||||
|
||||
if module.check_mode:
|
||||
return "%(pkgin)s -n %(command)s %(package)s" % vars
|
||||
@@ -283,6 +284,7 @@ def install_packages(module, packages):
|
||||
|
||||
module.exit_json(changed=False, msg="package(s) already present")
|
||||
|
||||
|
||||
def update_package_db(module):
|
||||
rc, out, err = module.run_command(
|
||||
format_pkgin_command(module, "update"))
|
||||
@@ -295,6 +297,7 @@ def update_package_db(module):
|
||||
else:
|
||||
module.fail_json(msg="could not update package db")
|
||||
|
||||
|
||||
def do_upgrade_packages(module, full=False):
|
||||
if full:
|
||||
cmd = "full-upgrade"
|
||||
@@ -310,12 +313,15 @@ def do_upgrade_packages(module, full=False):
|
||||
else:
|
||||
module.fail_json(msg="could not %s packages" % cmd)
|
||||
|
||||
|
||||
def upgrade_packages(module):
|
||||
do_upgrade_packages(module)
|
||||
|
||||
|
||||
def full_upgrade_packages(module):
|
||||
do_upgrade_packages(module, True)
|
||||
|
||||
|
||||
def clean_cache(module):
|
||||
rc, out, err = module.run_command(
|
||||
format_pkgin_command(module, "clean"))
|
||||
@@ -327,18 +333,19 @@ def clean_cache(module):
|
||||
else:
|
||||
module.fail_json(msg="could not clean package cache")
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
state = dict(default="present", choices=["present","absent"]),
|
||||
name = dict(aliases=["pkg"], type='list'),
|
||||
update_cache = dict(default='no', type='bool'),
|
||||
upgrade = dict(default='no', type='bool'),
|
||||
full_upgrade = dict(default='no', type='bool'),
|
||||
clean = dict(default='no', type='bool'),
|
||||
force = dict(default='no', type='bool')),
|
||||
required_one_of = [['name', 'update_cache', 'upgrade', 'full_upgrade', 'clean']],
|
||||
supports_check_mode = True)
|
||||
argument_spec=dict(
|
||||
state=dict(default="present", choices=["present", "absent"]),
|
||||
name=dict(aliases=["pkg"], type='list'),
|
||||
update_cache=dict(default='no', type='bool'),
|
||||
upgrade=dict(default='no', type='bool'),
|
||||
full_upgrade=dict(default='no', type='bool'),
|
||||
clean=dict(default='no', type='bool'),
|
||||
force=dict(default='no', type='bool')),
|
||||
required_one_of=[['name', 'update_cache', 'upgrade', 'full_upgrade', 'clean']],
|
||||
supports_check_mode=True)
|
||||
|
||||
global PKGIN_PATH
|
||||
PKGIN_PATH = module.get_bin_path('pkgin', True, ['/opt/local/bin'])
|
||||
|
||||
@@ -111,6 +111,7 @@ EXAMPLES = '''
|
||||
import re
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def query_package(module, pkgng_path, name, dir_arg):
|
||||
|
||||
rc, out, err = module.run_command("%s %s info -g -e %s" % (pkgng_path, dir_arg, name))
|
||||
@@ -120,6 +121,7 @@ def query_package(module, pkgng_path, name, dir_arg):
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def pkgng_older_than(module, pkgng_path, compare_version):
|
||||
|
||||
rc, out, err = module.run_command("%s -v" % pkgng_path)
|
||||
@@ -206,6 +208,7 @@ def install_packages(module, pkgng_path, packages, cached, pkgsite, dir_arg):
|
||||
|
||||
return (False, "package(s) already present")
|
||||
|
||||
|
||||
def annotation_query(module, pkgng_path, package, tag, dir_arg):
|
||||
rc, out, err = module.run_command("%s %s info -g -A %s" % (pkgng_path, dir_arg, package))
|
||||
match = re.search(r'^\s*(?P<tag>%s)\s*:\s*(?P<value>\w+)' % tag, out, flags=re.MULTILINE)
|
||||
@@ -219,10 +222,10 @@ def annotation_add(module, pkgng_path, package, tag, value, dir_arg):
|
||||
if not _value:
|
||||
# Annotation does not exist, add it.
|
||||
rc, out, err = module.run_command('%s %s annotate -y -A %s %s "%s"'
|
||||
% (pkgng_path, dir_arg, package, tag, value))
|
||||
% (pkgng_path, dir_arg, package, tag, value))
|
||||
if rc != 0:
|
||||
module.fail_json(msg="could not annotate %s: %s"
|
||||
% (package, out), stderr=err)
|
||||
% (package, out), stderr=err)
|
||||
return True
|
||||
elif _value != value:
|
||||
# Annotation exists, but value differs
|
||||
@@ -234,41 +237,43 @@ def annotation_add(module, pkgng_path, package, tag, value, dir_arg):
|
||||
# Annotation exists, nothing to do
|
||||
return False
|
||||
|
||||
|
||||
def annotation_delete(module, pkgng_path, package, tag, value, dir_arg):
|
||||
_value = annotation_query(module, pkgng_path, package, tag, dir_arg)
|
||||
if _value:
|
||||
rc, out, err = module.run_command('%s %s annotate -y -D %s %s'
|
||||
% (pkgng_path, dir_arg, package, tag))
|
||||
% (pkgng_path, dir_arg, package, tag))
|
||||
if rc != 0:
|
||||
module.fail_json(msg="could not delete annotation to %s: %s"
|
||||
% (package, out), stderr=err)
|
||||
% (package, out), stderr=err)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def annotation_modify(module, pkgng_path, package, tag, value, dir_arg):
|
||||
_value = annotation_query(module, pkgng_path, package, tag, dir_arg)
|
||||
if not value:
|
||||
# No such tag
|
||||
module.fail_json(msg="could not change annotation to %s: tag %s does not exist"
|
||||
% (package, tag))
|
||||
% (package, tag))
|
||||
elif _value == value:
|
||||
# No change in value
|
||||
return False
|
||||
else:
|
||||
rc,out,err = module.run_command('%s %s annotate -y -M %s %s "%s"'
|
||||
% (pkgng_path, dir_arg, package, tag, value))
|
||||
rc, out, err = module.run_command('%s %s annotate -y -M %s %s "%s"'
|
||||
% (pkgng_path, dir_arg, package, tag, value))
|
||||
if rc != 0:
|
||||
module.fail_json(msg="could not change annotation annotation to %s: %s"
|
||||
% (package, out), stderr=err)
|
||||
% (package, out), stderr=err)
|
||||
return True
|
||||
|
||||
|
||||
def annotate_packages(module, pkgng_path, packages, annotation, dir_arg):
|
||||
annotate_c = 0
|
||||
annotations = map(lambda _annotation:
|
||||
re.match(r'(?P<operation>[\+-:])(?P<tag>\w+)(=(?P<value>\w+))?',
|
||||
_annotation).groupdict(),
|
||||
re.split(r',', annotation))
|
||||
re.match(r'(?P<operation>[\+-:])(?P<tag>\w+)(=(?P<value>\w+))?',
|
||||
_annotation).groupdict(),
|
||||
re.split(r',', annotation))
|
||||
|
||||
operation = {
|
||||
'+': annotation_add,
|
||||
@@ -285,6 +290,7 @@ def annotate_packages(module, pkgng_path, packages, annotation, dir_arg):
|
||||
return (True, "added %s annotations." % annotate_c)
|
||||
return (False, "changed no annotations")
|
||||
|
||||
|
||||
def autoremove_packages(module, pkgng_path, dir_arg):
|
||||
rc, out, err = module.run_command("%s %s autoremove -n" % (pkgng_path, dir_arg))
|
||||
|
||||
@@ -302,20 +308,21 @@ def autoremove_packages(module, pkgng_path, dir_arg):
|
||||
|
||||
return True, "autoremoved %d package(s)" % (autoremove_c)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
state = dict(default="present", choices=["present","absent"], required=False),
|
||||
name = dict(aliases=["pkg"], required=True, type='list'),
|
||||
cached = dict(default=False, type='bool'),
|
||||
annotation = dict(default="", required=False),
|
||||
pkgsite = dict(default="", required=False),
|
||||
rootdir = dict(default="", required=False, type='path'),
|
||||
chroot = dict(default="", required=False, type='path'),
|
||||
jail = dict(default="", required=False, type='str'),
|
||||
autoremove = dict(default=False, type='bool')),
|
||||
supports_check_mode = True,
|
||||
mutually_exclusive =[["rootdir", "chroot", "jail"]])
|
||||
argument_spec=dict(
|
||||
state=dict(default="present", choices=["present", "absent"], required=False),
|
||||
name=dict(aliases=["pkg"], required=True, type='list'),
|
||||
cached=dict(default=False, type='bool'),
|
||||
annotation=dict(default="", required=False),
|
||||
pkgsite=dict(default="", required=False),
|
||||
rootdir=dict(default="", required=False, type='path'),
|
||||
chroot=dict(default="", required=False, type='path'),
|
||||
jail=dict(default="", required=False, type='str'),
|
||||
autoremove=dict(default=False, type='bool')),
|
||||
supports_check_mode=True,
|
||||
mutually_exclusive=[["rootdir", "chroot", "jail"]])
|
||||
|
||||
pkgng_path = module.get_bin_path('pkg', True)
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ EXAMPLES = '''
|
||||
import os
|
||||
import pipes
|
||||
|
||||
|
||||
def package_installed(module, name):
|
||||
cmd = ['pkginfo']
|
||||
cmd.append('-q')
|
||||
@@ -79,11 +80,12 @@ def package_installed(module, name):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def package_latest(module, name, site):
|
||||
# Only supports one package
|
||||
cmd = [ 'pkgutil', '-U', '--single', '-c' ]
|
||||
cmd = ['pkgutil', '-U', '--single', '-c']
|
||||
if site is not None:
|
||||
cmd += [ '-t', site]
|
||||
cmd += ['-t', site]
|
||||
cmd.append(name)
|
||||
rc, out, err = run_command(module, cmd)
|
||||
# replace | tail -1 |grep -v SAME
|
||||
@@ -91,45 +93,50 @@ def package_latest(module, name, site):
|
||||
# at the end of the list
|
||||
return 'SAME' in out.split('\n')[-2]
|
||||
|
||||
|
||||
def run_command(module, cmd, **kwargs):
|
||||
progname = cmd[0]
|
||||
cmd[0] = module.get_bin_path(progname, True, ['/opt/csw/bin'])
|
||||
return module.run_command(cmd, **kwargs)
|
||||
|
||||
|
||||
def package_install(module, state, name, site, update_catalog):
|
||||
cmd = [ 'pkgutil', '-iy' ]
|
||||
cmd = ['pkgutil', '-iy']
|
||||
if update_catalog:
|
||||
cmd += [ '-U' ]
|
||||
cmd += ['-U']
|
||||
if site is not None:
|
||||
cmd += [ '-t', site ]
|
||||
cmd += ['-t', site]
|
||||
if state == 'latest':
|
||||
cmd += [ '-f' ]
|
||||
cmd += ['-f']
|
||||
cmd.append(name)
|
||||
(rc, out, err) = run_command(module, cmd)
|
||||
return (rc, out, err)
|
||||
|
||||
|
||||
def package_upgrade(module, name, site, update_catalog):
|
||||
cmd = [ 'pkgutil', '-ufy' ]
|
||||
cmd = ['pkgutil', '-ufy']
|
||||
if update_catalog:
|
||||
cmd += [ '-U' ]
|
||||
cmd += ['-U']
|
||||
if site is not None:
|
||||
cmd += [ '-t', site ]
|
||||
cmd += ['-t', site]
|
||||
cmd.append(name)
|
||||
(rc, out, err) = run_command(module, cmd)
|
||||
return (rc, out, err)
|
||||
|
||||
|
||||
def package_uninstall(module, name):
|
||||
cmd = [ 'pkgutil', '-ry', name]
|
||||
cmd = ['pkgutil', '-ry', name]
|
||||
(rc, out, err) = run_command(module, cmd)
|
||||
return (rc, out, err)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
name = dict(required = True),
|
||||
state = dict(required = True, choices=['present', 'absent','latest']),
|
||||
site = dict(default = None),
|
||||
update_catalog = dict(required = False, default = False, type='bool'),
|
||||
argument_spec=dict(
|
||||
name=dict(required=True),
|
||||
state=dict(required=True, choices=['present', 'absent', 'latest']),
|
||||
site=dict(default=None),
|
||||
update_catalog=dict(required=False, default=False, type='bool'),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
@@ -289,7 +289,7 @@ def sync_repositories(module, webrsync=False):
|
||||
def emerge_packages(module, packages):
|
||||
p = module.params
|
||||
|
||||
if not (p['update'] or p['noreplace'] or p['state']=='latest'):
|
||||
if not (p['update'] or p['noreplace'] or p['state'] == 'latest'):
|
||||
for package in packages:
|
||||
if not query_package(module, package, 'emerge'):
|
||||
break
|
||||
@@ -319,7 +319,7 @@ def emerge_packages(module, packages):
|
||||
if p[flag]:
|
||||
args.append(arg)
|
||||
|
||||
if p['state'] and p['state']=='latest':
|
||||
if p['state'] and p['state'] == 'latest':
|
||||
args.append("--update")
|
||||
|
||||
if p['usepkg'] and p['usepkgonly']:
|
||||
|
||||
@@ -138,7 +138,7 @@ def remove_packages(module, packages):
|
||||
name_without_digits = re.sub('[0-9]', '', package)
|
||||
rc, out, err = module.run_command("%s `%s %s`" % (pkg_delete_path, pkg_glob_path,
|
||||
shlex_quote(name_without_digits)),
|
||||
use_unsafe_shell=True)
|
||||
use_unsafe_shell=True)
|
||||
if query_package(module, package):
|
||||
module.fail_json(msg="failed to remove %s: %s" % (package, out))
|
||||
|
||||
@@ -164,9 +164,9 @@ def install_packages(module, packages, use_packages):
|
||||
portinstall_path = module.get_bin_path('portinstall', True)
|
||||
|
||||
if use_packages == "yes":
|
||||
portinstall_params="--use-packages"
|
||||
portinstall_params = "--use-packages"
|
||||
else:
|
||||
portinstall_params=""
|
||||
portinstall_params = ""
|
||||
|
||||
for package in packages:
|
||||
if query_package(module, package):
|
||||
@@ -193,10 +193,10 @@ def install_packages(module, packages, use_packages):
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
state = dict(default="present", choices=["present","absent"]),
|
||||
name = dict(aliases=["pkg"], required=True),
|
||||
use_packages = dict(type='bool', default='yes')))
|
||||
argument_spec=dict(
|
||||
state=dict(default="present", choices=["present", "absent"]),
|
||||
name=dict(aliases=["pkg"], required=True),
|
||||
use_packages=dict(type='bool', default='yes')))
|
||||
|
||||
p = module.params
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ def remove_packages(module, slackpkg_path, packages):
|
||||
if not module.check_mode:
|
||||
rc, out, err = module.run_command("%s -default_answer=y -batch=on \
|
||||
remove %s" % (slackpkg_path,
|
||||
package))
|
||||
package))
|
||||
|
||||
if not module.check_mode and query_package(module, slackpkg_path,
|
||||
package):
|
||||
@@ -122,7 +122,7 @@ def install_packages(module, slackpkg_path, packages):
|
||||
if not module.check_mode:
|
||||
rc, out, err = module.run_command("%s -default_answer=y -batch=on \
|
||||
install %s" % (slackpkg_path,
|
||||
package))
|
||||
package))
|
||||
|
||||
if not module.check_mode and not query_package(module, slackpkg_path,
|
||||
package):
|
||||
@@ -145,7 +145,7 @@ def upgrade_packages(module, slackpkg_path, packages):
|
||||
if not module.check_mode:
|
||||
rc, out, err = module.run_command("%s -default_answer=y -batch=on \
|
||||
upgrade %s" % (slackpkg_path,
|
||||
package))
|
||||
package))
|
||||
|
||||
if not module.check_mode and not query_package(module, slackpkg_path,
|
||||
package):
|
||||
|
||||
@@ -607,17 +607,17 @@ def manage_spells(module):
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
name = dict(default=None, aliases=['spell'], type='list'),
|
||||
state = dict(default='present', choices=['present', 'latest',
|
||||
'absent', 'cast', 'dispelled', 'rebuild']),
|
||||
depends = dict(default=None),
|
||||
update = dict(default=False, type='bool'),
|
||||
update_cache = dict(default=False, aliases=['update_codex'], type='bool'),
|
||||
cache_valid_time = dict(default=0, type='int')
|
||||
argument_spec=dict(
|
||||
name=dict(default=None, aliases=['spell'], type='list'),
|
||||
state=dict(default='present', choices=['present', 'latest',
|
||||
'absent', 'cast', 'dispelled', 'rebuild']),
|
||||
depends=dict(default=None),
|
||||
update=dict(default=False, type='bool'),
|
||||
update_cache=dict(default=False, aliases=['update_codex'], type='bool'),
|
||||
cache_valid_time=dict(default=0, type='int')
|
||||
),
|
||||
required_one_of = [['name', 'update', 'update_cache']],
|
||||
supports_check_mode = True
|
||||
required_one_of=[['name', 'update', 'update_cache']],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
if os.geteuid() != 0:
|
||||
|
||||
@@ -105,6 +105,7 @@ EXAMPLES = '''
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
|
||||
def package_installed(module, name, category):
|
||||
cmd = [module.get_bin_path('pkginfo', True)]
|
||||
cmd.append('-q')
|
||||
@@ -117,6 +118,7 @@ def package_installed(module, name, category):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def create_admin_file():
|
||||
(desc, filename) = tempfile.mkstemp(prefix='ansible_svr4pkg', text=True)
|
||||
fullauto = '''
|
||||
@@ -141,48 +143,52 @@ basedir=default
|
||||
os.close(desc)
|
||||
return filename
|
||||
|
||||
|
||||
def run_command(module, cmd):
|
||||
progname = cmd[0]
|
||||
cmd[0] = module.get_bin_path(progname, True)
|
||||
return module.run_command(cmd)
|
||||
|
||||
|
||||
def package_install(module, name, src, proxy, response_file, zone, category):
|
||||
adminfile = create_admin_file()
|
||||
cmd = [ 'pkgadd', '-n']
|
||||
cmd = ['pkgadd', '-n']
|
||||
if zone == 'current':
|
||||
cmd += [ '-G' ]
|
||||
cmd += [ '-a', adminfile, '-d', src ]
|
||||
cmd += ['-G']
|
||||
cmd += ['-a', adminfile, '-d', src]
|
||||
if proxy is not None:
|
||||
cmd += [ '-x', proxy ]
|
||||
cmd += ['-x', proxy]
|
||||
if response_file is not None:
|
||||
cmd += [ '-r', response_file ]
|
||||
cmd += ['-r', response_file]
|
||||
if category:
|
||||
cmd += [ '-Y' ]
|
||||
cmd += ['-Y']
|
||||
cmd.append(name)
|
||||
(rc, out, err) = run_command(module, cmd)
|
||||
os.unlink(adminfile)
|
||||
return (rc, out, err)
|
||||
|
||||
|
||||
def package_uninstall(module, name, src, category):
|
||||
adminfile = create_admin_file()
|
||||
if category:
|
||||
cmd = [ 'pkgrm', '-na', adminfile, '-Y', name ]
|
||||
cmd = ['pkgrm', '-na', adminfile, '-Y', name]
|
||||
else:
|
||||
cmd = [ 'pkgrm', '-na', adminfile, name]
|
||||
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),
|
||||
proxy = dict(default = None),
|
||||
response_file = dict(default = None),
|
||||
zone = dict(required=False, default = 'all', choices=['current','all']),
|
||||
category = dict(default=False, type='bool')
|
||||
argument_spec=dict(
|
||||
name=dict(required=True),
|
||||
state=dict(required=True, choices=['present', 'absent']),
|
||||
src=dict(default=None),
|
||||
proxy=dict(default=None),
|
||||
response_file=dict(default=None),
|
||||
zone=dict(required=False, default='all', choices=['current', 'all']),
|
||||
category=dict(default=False, type='bool')
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
@@ -108,6 +108,7 @@ def query_package(module, name, depot=None):
|
||||
|
||||
return rc, version
|
||||
|
||||
|
||||
def remove_package(module, name):
|
||||
""" Uninstall package if installed. """
|
||||
|
||||
@@ -119,6 +120,7 @@ def remove_package(module, name):
|
||||
else:
|
||||
return rc, stderr
|
||||
|
||||
|
||||
def install_package(module, depot, name):
|
||||
""" Install package if not already installed """
|
||||
|
||||
@@ -129,12 +131,13 @@ def install_package(module, depot, name):
|
||||
else:
|
||||
return rc, stderr
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
name = dict(aliases=['pkg'], required=True),
|
||||
state = dict(choices=['present', 'absent', 'latest'], required=True),
|
||||
depot = dict(default=None, required=False)
|
||||
argument_spec=dict(
|
||||
name=dict(aliases=['pkg'], required=True),
|
||||
state=dict(choices=['present', 'absent', 'latest'], required=True),
|
||||
depot=dict(default=None, required=False)
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
@@ -145,12 +148,11 @@ def main():
|
||||
changed = False
|
||||
msg = "No changed"
|
||||
rc = 0
|
||||
if ( state == 'present' or state == 'latest' ) and depot is None:
|
||||
if (state == 'present' or state == 'latest') and depot is None:
|
||||
output = "depot parameter is mandatory in present or latest task"
|
||||
module.fail_json(name=name, msg=output, rc=rc)
|
||||
|
||||
|
||||
#Check local version
|
||||
# Check local version
|
||||
rc, version_installed = query_package(module, name)
|
||||
if not rc:
|
||||
installed = True
|
||||
@@ -159,7 +161,7 @@ def main():
|
||||
else:
|
||||
installed = False
|
||||
|
||||
if ( state == 'present' or state == 'latest' ) and installed is False:
|
||||
if (state == 'present' or state == 'latest') and installed is False:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
rc, output = install_package(module, depot, name)
|
||||
@@ -172,14 +174,14 @@ def main():
|
||||
module.fail_json(name=name, msg=output, rc=rc)
|
||||
|
||||
elif state == 'latest' and installed is True:
|
||||
#Check depot version
|
||||
# Check depot version
|
||||
rc, version_depot = query_package(module, name, depot)
|
||||
|
||||
if not rc:
|
||||
if compare_package(version_installed,version_depot) == -1:
|
||||
if compare_package(version_installed, version_depot) == -1:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
#Install new version
|
||||
# Install new version
|
||||
rc, output = install_package(module, depot, name)
|
||||
|
||||
if not rc:
|
||||
|
||||
@@ -204,7 +204,6 @@ class Package:
|
||||
return self.prefix + self.name + self.version
|
||||
|
||||
|
||||
|
||||
def split_name_version(name):
|
||||
"""splits of the package name and desired version
|
||||
|
||||
@@ -301,7 +300,7 @@ def parse_zypper_xml(m, cmd, fail_not_found=True, packages=None):
|
||||
return parse_zypper_xml(m, cmd, fail_not_found=fail_not_found, packages=packages)
|
||||
|
||||
return packages, rc, stdout, stderr
|
||||
m.fail_json(msg='Zypper run command failed with return code %s.'%rc, rc=rc, stdout=stdout, stderr=stderr, cmd=cmd)
|
||||
m.fail_json(msg='Zypper run command failed with return code %s.' % rc, rc=rc, stdout=stdout, stderr=stderr, cmd=cmd)
|
||||
|
||||
|
||||
def get_cmd(m, subcommand):
|
||||
@@ -455,20 +454,21 @@ def repo_refresh(m):
|
||||
# ===========================================
|
||||
# Main control flow
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
name = dict(required=True, aliases=['pkg'], type='list'),
|
||||
state = dict(required=False, default='present', choices=['absent', 'installed', 'latest', 'present', 'removed', 'dist-upgrade']),
|
||||
type = dict(required=False, default='package', choices=['package', 'patch', 'pattern', 'product', 'srcpackage', 'application']),
|
||||
disable_gpg_check = dict(required=False, default='no', type='bool'),
|
||||
disable_recommends = dict(required=False, default='yes', type='bool'),
|
||||
force = dict(required=False, default='no', type='bool'),
|
||||
update_cache = dict(required=False, aliases=['refresh'], default='no', type='bool'),
|
||||
oldpackage = dict(required=False, default='no', type='bool'),
|
||||
extra_args = dict(required=False, default=None),
|
||||
argument_spec=dict(
|
||||
name=dict(required=True, aliases=['pkg'], type='list'),
|
||||
state=dict(required=False, default='present', choices=['absent', 'installed', 'latest', 'present', 'removed', 'dist-upgrade']),
|
||||
type=dict(required=False, default='package', choices=['package', 'patch', 'pattern', 'product', 'srcpackage', 'application']),
|
||||
disable_gpg_check=dict(required=False, default='no', type='bool'),
|
||||
disable_recommends=dict(required=False, default='yes', type='bool'),
|
||||
force=dict(required=False, default='no', type='bool'),
|
||||
update_cache=dict(required=False, aliases=['refresh'], default='no', type='bool'),
|
||||
oldpackage=dict(required=False, default='no', type='bool'),
|
||||
extra_args=dict(required=False, default=None),
|
||||
),
|
||||
supports_check_mode = True
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
name = module.params['name']
|
||||
|
||||
@@ -146,6 +146,7 @@ REPO_OPTS = ['alias', 'name', 'priority', 'enabled', 'autorefresh', 'gpgcheck']
|
||||
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
|
||||
def _get_cmd(*args):
|
||||
"""Combines the non-interactive zypper command with arguments/subcommands"""
|
||||
cmd = ['/usr/bin/zypper', '--quiet', '--non-interactive']
|
||||
@@ -178,6 +179,7 @@ def _parse_repos(module):
|
||||
else:
|
||||
module.fail_json(msg='Failed to execute "%s"' % " ".join(cmd), rc=rc, stdout=stdout, stderr=stderr)
|
||||
|
||||
|
||||
def _repo_changes(realrepo, repocmp):
|
||||
"Check whether the 2 given repos have different settings."
|
||||
for k in repocmp:
|
||||
@@ -194,6 +196,7 @@ def _repo_changes(realrepo, repocmp):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def repo_exists(module, repodata, overwrite_multiple):
|
||||
"""Check whether the repository already exists.
|
||||
|
||||
@@ -288,6 +291,7 @@ def get_zypper_version(module):
|
||||
return LooseVersion('1.0')
|
||||
return LooseVersion(stdout.split()[1])
|
||||
|
||||
|
||||
def runrefreshrepo(module, auto_import_keys=False, shortname=None):
|
||||
"Forces zypper to refresh repo metadata."
|
||||
if auto_import_keys:
|
||||
@@ -309,15 +313,15 @@ def main():
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
runrefresh=dict(required=False, default='no', type='bool'),
|
||||
description=dict(required=False),
|
||||
disable_gpg_check = dict(required=False, default=False, type='bool'),
|
||||
autorefresh = dict(required=False, default=True, type='bool', aliases=['refresh']),
|
||||
priority = dict(required=False, type='int'),
|
||||
enabled = dict(required=False, default=True, type='bool'),
|
||||
overwrite_multiple = dict(required=False, default=False, type='bool'),
|
||||
auto_import_keys = dict(required=False, default=False, type='bool'),
|
||||
disable_gpg_check=dict(required=False, default=False, type='bool'),
|
||||
autorefresh=dict(required=False, default=True, type='bool', aliases=['refresh']),
|
||||
priority=dict(required=False, type='int'),
|
||||
enabled=dict(required=False, default=True, type='bool'),
|
||||
overwrite_multiple=dict(required=False, default=False, type='bool'),
|
||||
auto_import_keys=dict(required=False, default=False, type='bool'),
|
||||
),
|
||||
supports_check_mode=False,
|
||||
required_one_of = [['state','runrefresh']],
|
||||
required_one_of=[['state', 'runrefresh']],
|
||||
)
|
||||
|
||||
repo = module.params['repo']
|
||||
|
||||
Reference in New Issue
Block a user