From 5ed21bf443a7f2e1131fbd6c51448bff112fcded Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 6 Aug 2012 20:07:02 -0400 Subject: [PATCH] whitespace + remove deprecated YAML parser (migration script lives in examples/scripts and warning was added in 0.6 release) --- apt | 8 +++--- assemble | 18 ++++++------ async_status | 2 +- async_wrapper | 8 +++--- authorized_key | 16 +++++------ copy | 6 ++-- file | 18 ++++++------ get_url | 28 +++++++++--------- git | 2 +- group | 2 +- mount | 46 ++++++++++++++--------------- service | 18 ++++++------ setup | 4 +-- shell | 4 +-- virt | 42 +++++++++++++-------------- yum | 78 +++++++++++++++++++++++++------------------------- 16 files changed, 150 insertions(+), 150 deletions(-) diff --git a/apt b/apt index 7b3bda79c1c..ff7dd8a231a 100755 --- a/apt +++ b/apt @@ -77,7 +77,7 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None, install_reco installed, upgradable = package_status(m, name, version, cache) if not installed or (upgrade and upgradable): packages += "'%s' " % package - + if len(packages) != 0: if force: force_yes = '--force-yes' @@ -105,7 +105,7 @@ def remove(m, pkgspec, cache, purge=False): installed, upgradable = package_status(m, name, version, cache) if installed: packages += "'%s' " % package - + if len(packages) == 0: m.exit_json(changed=False) else: @@ -157,9 +157,9 @@ def main(): module.exit_json(changed=False) force_yes = module.boolean(p['force']) - + packages = p['package'].split(',') - latest = p['state'] == 'latest' + latest = p['state'] == 'latest' for package in packages: if package.count('=') > 1: module.fail_json(msg="invalid package spec: %s" % package) diff --git a/assemble b/assemble index 5c9556a07ef..400438cb0e9 100755 --- a/assemble +++ b/assemble @@ -45,39 +45,39 @@ def write_temp_file(data): # main def main(): - + module = AnsibleModule( argument_spec = dict( src = dict(required=True), dest = dict(required=True), ) ) - + changed=False pathmd5 = None destmd5 = None src = os.path.expanduser(module.params['src']) dest = os.path.expanduser(module.params['dest']) - + if not os.path.exists(src): module.fail_json(msg="Source (%s) does not exist" % src) - + if not os.path.isdir(src): module.fail_json(msg="Source (%s) is not a directory" % src) - + path = write_temp_file(assemble_from_fragments(src)) pathmd5 = module.md5(path) - + if os.path.exists(dest): destmd5 = module.md5(dest) - + if pathmd5 != destmd5: shutil.copy(path, dest) changed = True - + # Mission complete - module.exit_json(src=src, dest=dest, md5sum=destmd5, + module.exit_json(src=src, dest=dest, md5sum=destmd5, changed=changed, msg="OK", daisychain="file", daisychain_args=module.params) diff --git a/async_status b/async_status index 811c67c9765..404cb177685 100755 --- a/async_status +++ b/async_status @@ -55,7 +55,7 @@ def main(): # file not written yet? That means it is running module.exit_json(results_file=log_path, ansible_job_id=jid, started=1) else: - module_fail_json(ansible_job_id=jid, results_file=log_path, + module_fail_json(ansible_job_id=jid, results_file=log_path, msg="Could not parse job output: %s" % data) if not data.has_key("started"): diff --git a/async_wrapper b/async_wrapper index 753c29e9d6c..d1a87259823 100755 --- a/async_wrapper +++ b/async_wrapper @@ -63,7 +63,7 @@ def daemonize_self(): dev_null = file('/dev/null','rw') os.dup2(dev_null.fileno(), sys.stdin.fileno()) os.dup2(dev_null.fileno(), sys.stdout.fileno()) - os.dup2(dev_null.fileno(), sys.stderr.fileno()) + os.dup2(dev_null.fileno(), sys.stderr.fileno()) if len(sys.argv) < 3: print json.dumps({ @@ -101,11 +101,11 @@ def _run_command(wrapped_cmd, jid, log_path): logfile.close() logfile = open(log_path, "w") result = {} - + outdata = '' try: cmd = shlex.split(wrapped_cmd) - script = subprocess.Popen(cmd, shell=False, + script = subprocess.Popen(cmd, shell=False, stdin=None, stdout=logfile, stderr=logfile) script.communicate() outdata = file(log_path).read() @@ -125,7 +125,7 @@ def _run_command(wrapped_cmd, jid, log_path): "cmd" : wrapped_cmd, "data" : outdata, # temporary debug only "msg" : traceback.format_exc() - } + } result['ansible_job_id'] = jid logfile.write(json.dumps(result)) logfile.close() diff --git a/authorized_key b/authorized_key index 67108c9f68d..8ecd542f8df 100755 --- a/authorized_key +++ b/authorized_key @@ -38,7 +38,7 @@ import os.path def keyfile(user, write=False): """ - Calculate name of authorized keys file, optionally creating the + Calculate name of authorized keys file, optionally creating the directories and file, properly setting permissions. :param str user: name of user in passwd file @@ -51,13 +51,13 @@ def keyfile(user, write=False): sshdir = os.path.join(homedir, ".ssh") keysfile = os.path.join(sshdir, "authorized_keys") - if not write: + if not write: return keysfile uid = user_entry.pw_uid gid = user_entry.pw_gid - if not os.path.exists(sshdir): + if not os.path.exists(sshdir): os.mkdir(sshdir, 0700) os.chown(sshdir, uid, gid) os.chmod(sshdir, 0700) @@ -74,7 +74,7 @@ def keyfile(user, write=False): def readkeys(filename): - if not os.path.isfile(filename): + if not os.path.isfile(filename): return [] f = open(filename) keys = [line.rstrip() for line in f.readlines()] @@ -97,19 +97,19 @@ def enforce_state(module, params): state = params.get("state", "present") # check current state -- just get the filename, don't create file - params["keyfile"] = keyfile(user, write=False) + params["keyfile"] = keyfile(user, write=False) keys = readkeys(params["keyfile"]) present = key in keys # handle idempotent state=present if state=="present": - if present: + if present: module.exit_json(changed=False) keys.append(key) writekeys(keyfile(user,write=True), keys) elif state=="absent": - if not present: + if not present: module.exit_json(changed=False) keys.remove(key) writekeys(keyfile(user,write=True), keys) @@ -133,4 +133,4 @@ def main(): # this is magic, see lib/ansible/module_common.py #<> -main() +main() diff --git a/copy b/copy index a5aef64cd5e..b168d7d0995 100755 --- a/copy +++ b/copy @@ -30,7 +30,7 @@ def main(): src=dict(required=True), dest=dict(required=True) ) - ) + ) src = os.path.expanduser(module.params['src']) dest = os.path.expanduser(module.params['dest']) @@ -60,9 +60,9 @@ def main(): try: shutil.copyfile(src, dest) except shutil.Error: - module.fail_json(msg="failed to copy: %s and %s are the same" % (src, dest)) + module.fail_json(msg="failed to copy: %s and %s are the same" % (src, dest)) except IOError: - module.fail_json(msg="failed to copy: %s to %s" % (src, dest)) + module.fail_json(msg="failed to copy: %s to %s" % (src, dest)) changed = True else: changed = False diff --git a/file b/file index 6acfb259249..2ae5c6d27d2 100755 --- a/file +++ b/file @@ -47,7 +47,7 @@ def add_path_info(kwargs): kwargs['secontext'] = ':'.join(selinux_context(path)) else: kwargs['state'] = 'absent' - return kwargs + return kwargs def module_exit_json(**kwargs): add_path_info(kwargs) @@ -155,7 +155,7 @@ def set_context_if_different(path, context, changed): module_fail_json(path=path, msg='set selinux context failed') changed = True return changed - + def set_owner_if_different(path, owner, changed): if owner is None: return changed @@ -167,7 +167,7 @@ def set_owner_if_different(path, owner, changed): return True return changed - + def set_group_if_different(path, group, changed): if group is None: return changed @@ -186,8 +186,8 @@ def set_mode_if_different(path, mode, changed): # FIXME: support English modes mode = int(mode, 8) except Exception, e: - module_fail_json(path=path, msg='mode needs to be something octalish', details=str(e)) - + module_fail_json(path=path, msg='mode needs to be something octalish', details=str(e)) + st = os.stat(path) prev_mode = stat.S_IMODE(st[stat.ST_MODE]) @@ -290,7 +290,7 @@ def main(): module_exit_json(path=path, changed=False) if state == 'file': - + if prev_state == 'absent': module_fail_json(path=path, msg='file does not exist, use copy or template module to create') @@ -307,7 +307,7 @@ def main(): if prev_state == 'absent': os.makedirs(path) changed = True - + # set modes owners and context as needed changed = set_context_if_different(path, secontext, changed) changed = set_owner_if_different(path, owner, changed) @@ -317,14 +317,14 @@ def main(): module_exit_json(path=path, changed=changed) elif state == 'link': - + if os.path.isabs(src): abs_src = src else: abs_src = os.path.join(os.path.dirname(dest), src) if not os.path.exists(abs_src): module_fail_json(path=path, src=src, msg='src file does not exist') - + if prev_state == 'absent': os.symlink(src, path) changed = True diff --git a/get_url b/get_url index 52cf640a63f..c503383c6ae 100755 --- a/get_url +++ b/get_url @@ -27,14 +27,14 @@ import tempfile HAS_URLLIB2=True try: import urllib2 -except ImportError: +except ImportError: HAS_URLLIB2=False HAS_URLPARSE=True try: import urlparse import socket -except ImportError: +except ImportError: HAS_URLPARSE=False # ============================================================== @@ -92,7 +92,7 @@ def url_do_get(module, url, dest): def url_get(module, url, dest): """ - Download url and store at dest. + Download url and store at dest. If dest is a directory, determine filename from url. Return (tempfile, info about the request) """ @@ -123,8 +123,8 @@ def url_get(module, url, dest): # main def main(): - - # does this really happen on non-ancient python? + + # does this really happen on non-ancient python? if not HAS_URLLIB2: module.fail_json(msg="urllib2 is not installed") if not HAS_URLPARSE: @@ -138,16 +138,16 @@ def main(): dest = dict(required=True), ) ) - + url = module.params['url'] dest = os.path.expanduser(module.params['dest']) - + # download to tmpsrc tmpsrc, info = url_get(module, url, dest) md5sum_src = None md5sum_dest = None dest = info['actualdest'] - + # raise an error if there is no tmpsrc file if not os.path.exists(tmpsrc): os.remove(tmpsrc) @@ -156,7 +156,7 @@ def main(): os.remove(tmpsrc) module.fail_json( msg="Source %s not readable" % (tmpsrc)) md5sum_src = module.md5(tmpsrc) - + # check if there is no dest file if os.path.exists(dest): # raise an error if copy has no permission on dest @@ -171,22 +171,22 @@ def main(): if not os.access(os.path.dirname(dest), os.W_OK): os.remove(tmpsrc) module.fail_json( msg="Destination %s not writable" % (os.path.dirname(dest))) - + if md5sum_src != md5sum_dest: try: shutil.copyfile(tmpsrc, dest) except Exception, err: os.remove(tmpsrc) - module.fail_json(msg="failed to copy %s to %s: %s" % (tmpsrc, dest, str(err))) + module.fail_json(msg="failed to copy %s to %s: %s" % (tmpsrc, dest, str(err))) changed = True else: changed = False - + os.remove(tmpsrc) # Mission complete - module.exit_json(url=url, dest=dest, src=tmpsrc, md5sum=md5sum_src, - changed=changed, msg=info.get('msg',''), + module.exit_json(url=url, dest=dest, src=tmpsrc, md5sum=md5sum_src, + changed=changed, msg=info.get('msg',''), daisychain="file", daisychain_args=info.get('daisychain_args','')) # this is magic, see lib/ansible/module_common.py diff --git a/git b/git index 392a7d5ddc4..bc82a97c062 100755 --- a/git +++ b/git @@ -166,7 +166,7 @@ def main(): if rc != 0: module.fail_json(msg=err) else: - # else do a pull + # else do a pull before = get_version(dest) (rc, out, err) = reset(dest) if rc != 0: diff --git a/group b/group index 00e2ebc790e..23e8703c496 100755 --- a/group +++ b/group @@ -80,7 +80,7 @@ def group_info(group): except KeyError: return False return info - + # =========================================== def main(): diff --git a/mount b/mount index 650458cc8b8..364f884a0c7 100755 --- a/mount +++ b/mount @@ -23,8 +23,8 @@ # mount module - mount fs and define in fstab # usage: # -# mount name=mountpoint, src=device_to_be_mounted fstype=fstype -# opts=mount_opts, dump=0 passno=0 state=[present|absent|mounted|unmounted] +# mount name=mountpoint, src=device_to_be_mounted fstype=fstype +# opts=mount_opts, dump=0 passno=0 state=[present|absent|mounted|unmounted] # # absent == remove from fstab and unmounted # present == add to fstab, do not change mount state @@ -52,7 +52,7 @@ def set_mount(**kwargs): ) args.update(kwargs) - new_line = '%(src)s %(name)s %(fstype)s %(opts)s %(dump)s %(passno)s\n' + new_line = '%(src)s %(name)s %(fstype)s %(opts)s %(dump)s %(passno)s\n' to_write = [] exists = False @@ -69,7 +69,7 @@ def set_mount(**kwargs): # but it is not our fault so leave it be to_write.append(line) continue - + ld = {} ld['src'], ld['name'], ld['fstype'], ld['opts'], ld['dump'], ld['passno'] = line.split() @@ -88,16 +88,16 @@ def set_mount(**kwargs): to_write.append(new_line % ld) else: to_write.append(line) - + if not exists: to_write.append(new_line % args) changed = True - + if changed: write_fstab(to_write, args['fstab']) return (args['name'], changed) - + def unset_mount(**kwargs): """ remove a mount point from fstab """ @@ -125,7 +125,7 @@ def unset_mount(**kwargs): # but it is not our fault so leave it be to_write.append(line) continue - + ld = {} ld['src'], ld['name'], ld['fstype'], ld['opts'], ld['dump'], ld['passno'] = line.split() @@ -141,7 +141,7 @@ def unset_mount(**kwargs): return (args['name'], changed) - + def mount(**kwargs): """ mount up a path or remount if needed """ @@ -185,7 +185,7 @@ def main(): fstab = dict(default=None) ) ) - + changed = False rc = 0 args = { @@ -201,12 +201,12 @@ def main(): args['dump'] = module.params['dump'] if module.params['fstab'] is not None: args['fstab'] = module.params['fstab'] - + # absent == remove from fstab and unmounted # unmounted == do not change fstab state, but unmount # present == add to fstab, do not change mount state # mounted == add to fstab if not there and make sure it is mounted, if it has changed in fstab then remount it - + state = module.params['state'] name = module.params['name'] if state == 'absent': @@ -216,24 +216,24 @@ def main(): res,msg = umount(**args) if res: fail_json(msg="Error unmounting %s: %s" % (name, msg)) - + if os.path.exists(name): try: os.rmdir(name) except (OSError, IOError), e: fail_json(msg="Error rmdir %s: %s" % (name, str(e))) - + module.exit_json(changed=changed, **args) - + if state == 'unmounted': if os.path.ismount(name): res,msg = umount(**args) if res: fail_json(msg="Error unmounting %s: %s" % (name, msg)) changed = True - + module.exit_json(changed=changed, **args) - + if state in ['mounted', 'present']: name, changed = set_mount(**args) if state == 'mounted': @@ -242,7 +242,7 @@ def main(): os.makedirs(name) except (OSError, IOError), e: fail_json(msg="Error making dir %s: %s" % (name, str(e))) - + res = 0 if os.path.ismount(name): if changed: @@ -250,16 +250,16 @@ def main(): else: changed = True res,msg = mount(**args) - + if res: fail_json(msg="Error mounting %s: %s" % (name, msg)) - - + + module.exit_json(changed=changed, **args) - + module.fail_json(msg='Unexpected position reached') sys.exit(0) - + # this is magic, see lib/ansible/module_common.py #<> main() diff --git a/service b/service index 27207071169..166686720df 100755 --- a/service +++ b/service @@ -101,14 +101,14 @@ def _get_service_status(name): # iptables status command output is lame # TODO: lookup if we can use a return code for this instead? running = True - + return running def _run(cmd): # returns (rc, stdout, stderr) from shell command process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) stdout, stderr = process.communicate() - return (process.returncode, stdout, stderr) + return (process.returncode, stdout, stderr) def _do_enable(name, enable): @@ -126,9 +126,9 @@ def _do_enable(name, enable): rc, stdout, stderr = _run("%s %s %s" % (CHKCONFIG, name, valid_argument['on'])) else: rc, stdout, stderr = _run("%s %s %s" % (CHKCONFIG, name, valid_argument['off'])) - + return rc, stdout, stderr - + def main(): module = AnsibleModule( argument_spec = dict( @@ -145,7 +145,7 @@ def main(): # =========================================== # find binaries locations on minion _find_binaries(module) - + # =========================================== # get service status running = _get_service_status(name) @@ -156,7 +156,7 @@ def main(): rc = 0 err = '' out = '' - + if module.params['enabled']: rc_enable, out_enable, err_enable = _do_enable(name, enable) rc += rc_enable @@ -208,10 +208,10 @@ def main(): result['state'] = state rc, stdout, stderr = _run("%s %s status" % (SERVICE, name)) module.exit_json(**result); - -# this is magic, see lib/ansible/module_common.py -#<> + +# this is magic, see lib/ansible/module_common.py +#<> main() diff --git a/setup b/setup index 42e1ea42afb..8284a51aedf 100755 --- a/setup +++ b/setup @@ -360,7 +360,7 @@ class FreeBSDHardware(Hardware): # Get swapinfo. swapinfo output looks like: # Device 1M-blocks Used Avail Capacity # /dev/ada0p3 314368 0 314368 0% - # + # cmd = subprocess.Popen("/usr/sbin/swapinfo -m", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = cmd.communicate() @@ -601,7 +601,7 @@ def run_setup(module): setup_options = {} facts = ansible_facts() - + for (k, v) in facts.items(): setup_options["ansible_%s" % k] = v diff --git a/shell b/shell index 3c8e63d4f4b..4999290c952 100644 --- a/shell +++ b/shell @@ -1,3 +1,3 @@ -# There is actually no actual shell module source, when you use 'shell' in ansible, -# it runs the 'command' module with special arguments and it behaves differently. +# There is actually no actual shell module source, when you use 'shell' in ansible, +# it runs the 'command' module with special arguments and it behaves differently. # See the command source and the comment "#USE_SHELL". diff --git a/virt b/virt index fdbf1fc86c9..3ed6dedda56 100755 --- a/virt +++ b/virt @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python # -*- coding: utf-8 -*- """ @@ -24,9 +24,9 @@ try: except ImportError: print "failed=True msg='libvirt python module unavailable'" sys.exit(1) - + ALL_COMMANDS = [] -VM_COMMANDS = ['create','status', 'start', 'stop', 'pause', 'unpause', +VM_COMMANDS = ['create','status', 'start', 'stop', 'pause', 'unpause', 'shutdown', 'undefine', 'destroy', 'get_xml', 'autostart'] HOST_COMMANDS = ['freemem', 'list_vms', 'info', 'nodeinfo', 'virttype'] ALL_COMMANDS.extend(VM_COMMANDS) @@ -141,11 +141,11 @@ class LibvirtConnection(object): def get_autostart(self, vmid): vm = self.conn.lookupByName(vmid) return vm.autostart() - + def set_autostart(self, vmid, val): vm = self.conn.lookupByName(vmid) return vm.setAutostart(val) - + class Virt(object): @@ -157,7 +157,7 @@ class Virt(object): def get_vm(self, vmid): self.__get_conn() return self.conn.find_vm(vmid) - + def state(self): vms = self.list_vms() state = [] @@ -216,7 +216,7 @@ class Virt(object): def virttype(self): return self.__get_conn().get_type() - + def autostart(self, vmid): self.conn = self.__get_conn() return self.conn.set_autostart(vmid, True) @@ -313,26 +313,26 @@ def core(module): v = Virt() res = {} - - + + if state: if not guest: module.fail_json(msg = "state change requires a guest specified") - + res['changed'] = False if state == 'running': if v.status(guest) is not 'running': - res['changed'] = True + res['changed'] = True res['msg'] = v.start(guest) elif state == 'shutdown': if v.status(guest) is not 'shutdown': res['changed'] = True res['msg'] = v.shutdown(guest) else: - module.fail_json(msg="unexpected state") - + module.fail_json(msg="unexpected state") + return VIRT_SUCCESS, res - + if command: if command in VM_COMMANDS: if not guest: @@ -341,20 +341,20 @@ def core(module): if type(res) != dict: res = { command: res } return VIRT_SUCCESS, res - + elif hasattr(v, command): res = getattr(v, command)() if type(res) != dict: res = { command: res } return VIRT_SUCCESS, res - + else: module.fail_json(msg="Command %s not recognized" % basecmd) - - module.fail_json(msg="expected state or command parameter to be specified") - + + module.fail_json(msg="expected state or command parameter to be specified") + def main(): - + module = AnsibleModule(argument_spec=dict( name = dict(aliases=['guest']), state = dict(choices=['running', 'shutdown']), @@ -375,4 +375,4 @@ def main(): # this is magic, see lib/ansible/module_common.py #<> -main() +main() diff --git a/yum b/yum index 0cecc15d6c4..85249af780c 100755 --- a/yum +++ b/yum @@ -33,7 +33,7 @@ def is_installed(repoq, pkgspec, qf=def_qf): rc,out,err = run(cmd) if rc == 0: return [ p for p in out.split('\n') if p.strip() ] - + return [] def is_available(repoq, pkgspec, qf=def_qf): @@ -50,7 +50,7 @@ def is_update(repoq, pkgspec, qf=def_qf): rc,out,err = run(cmd) if rc == 0: return set([ p for p in out.split('\n') if p.strip() ]) - + return [] @@ -60,26 +60,26 @@ def what_provides(repoq, req_spec, qf=def_qf): ret = [] if rc == 0: ret = set([ p for p in out.split('\n') if p.strip() ]) - + return ret def local_nvra(path): """return nvra of a local rpm passed in""" - + cmd = "/bin/rpm -qp --qf='%%{name}-%%{version}-%%{release}.%%{arch}\n' %s'" % path rc, out, err = run(cmd) if rc != 0: return None nvra = out.split('\n')[0] return nvra - - + + def pkg_to_dict(pkgstr): if pkgstr.strip(): n,e,v,r,a,repo = pkgstr.split('|') else: return {'error_parsing': pkgstr} - + d = { 'name':n, 'arch':a, @@ -89,7 +89,7 @@ def pkg_to_dict(pkgstr): 'repo':repo, 'nevra': '%s:%s-%s-%s.%s' % (e,n,v,r,a) } - + if repo == 'installed': d['yumstate'] = 'installed' else: @@ -103,16 +103,16 @@ def repolist(repoq, qf="%{repoid}"): ret = [] if rc == 0: ret = set([ p for p in out.split('\n') if p.strip() ]) - + return ret - + def list_stuff(conf_file, stuff): qf = "%{name}|%{epoch}|%{version}|%{release}|%{arch}|%{repoid}" repoq = '%s --plugins --quiet -q ' % repoquery if conf_file and os.path.exists(conf_file): repoq = '%s -c %s --plugins --quiet -q ' % (repoquery,conf_file) - + if stuff == 'installed': return [ pkg_to_dict(p) for p in is_installed(repoq, '-a', qf=qf) if p.strip() ] elif stuff == 'updates': @@ -126,7 +126,7 @@ def list_stuff(conf_file, stuff): def run(command): try: - cmd = subprocess.Popen(command, shell=True, + cmd = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = cmd.communicate() except (OSError, IOError), e: @@ -144,7 +144,7 @@ def run(command): err = '' else: rc = cmd.returncode - + return rc, out, err @@ -161,8 +161,8 @@ def install(module, items, repoq, yum_basecmd): # check if pkgspec is installed (if possible for idempotence) # localpkg if spec.endswith('.rpm'): - # get the pkg name-v-r.arch - nvra = local_nvra(spec) + # get the pkg name-v-r.arch + nvra = local_nvra(spec) # look for them in the rpmdb if is_installed(repoq, nvra): # if they are there, skip it @@ -181,23 +181,23 @@ def install(module, items, repoq, yum_basecmd): res['msg'] += "No Package matching '%s' found available, installed or updated" % spec res['failed'] = True module.exit_json(**res) - + # if any of them are installed # then nothing to do - + found = False for this in pkglist: if is_installed(repoq, this): found = True res['results'].append('%s providing %s is already installed' % (this, spec)) - + if found: continue # if not - then pass in the spec as what to install - # we could get here if nothing provides it but that's not - # the error we're catching here + # we could get here if nothing provides it but that's not + # the error we're catching here pkg = spec - + cmd = "%s install '%s'" % (yum_basecmd, pkg) rc, out, err = run(cmd) # FIXME - if we did an install - go and check the rpmdb to see if it actually installed @@ -213,9 +213,9 @@ def install(module, items, repoq, yum_basecmd): res['rc'] = 0 res['results'].append(out) res['msg'] += err - + module.exit_json(**res) - + def remove(module, items, repoq, yum_basecmd): res = {} @@ -223,7 +223,7 @@ def remove(module, items, repoq, yum_basecmd): res['msg'] = '' res['changed'] = False res['rc'] = 0 - + for spec in items: pkg = None @@ -237,12 +237,12 @@ def remove(module, items, repoq, yum_basecmd): res['msg'] += "No Package matching '%s' found available, installed or updated" % spec res['failed']=True module.exit_json(**res) - + found = False for this in pkglist: if is_installed(repoq, this): found = True - + if not found: res['results'].append('%s is not installed' % spec) continue @@ -250,7 +250,7 @@ def remove(module, items, repoq, yum_basecmd): cmd = "%s remove '%s'" % (yum_basecmd, pkg) rc, out, err = run(cmd) - + # FIXME if we ran the remove - check to make sure it actually removed :( # look for the pkg in the rpmdb - this is notoriously hard for groups :( if rc != 0: @@ -264,7 +264,7 @@ def remove(module, items, repoq, yum_basecmd): res['rc'] = 0 res['results'].append(out) res['msg'] += err - + module.exit_json(**res) def latest(module, items, repoq, yum_basecmd): @@ -273,7 +273,7 @@ def latest(module, items, repoq, yum_basecmd): res['msg'] = '' res['changed'] = False res['rc'] = 0 - + for spec in items: pkg = None @@ -296,11 +296,11 @@ def latest(module, items, repoq, yum_basecmd): found = True else: nothing_to_do = True - + if nothing_to_do: res['results'].append("All packages providing %s are up to date" % spec) continue - + if not found: basecmd = 'install' else: @@ -333,16 +333,16 @@ def latest(module, items, repoq, yum_basecmd): res['rc'] = 0 res['results'].append(out) res['msg'] += err - + module.exit_json(**res) - + def ensure(module, state, pkgspec, conf_file): res = {} stdout = "" stderr = "" - + # take multiple args comma separated items = [pkgspec] if pkgspec.find(',') != -1: @@ -361,9 +361,9 @@ def ensure(module, state, pkgspec, conf_file): elif state == 'latest': latest(module, items, repoq, yum_basecmd) - # should be caught by AnsibleModule argument_spec + # should be caught by AnsibleModule argument_spec return dict(changed=False, failed=True, results='', errors='unexpected state') - + def remove_only(pkgspec): # remove this pkg and only this pkg - fail if it will require more to remove @@ -380,7 +380,7 @@ def main(): # list=available # list=repos # list=pkgspec - + module = AnsibleModule( argument_spec = dict( pkg=dict(aliases=['name']), @@ -400,11 +400,11 @@ def main(): if not os.path.exists(repoquery): module.fail_json(msg="%s is required to run this module. Please install the yum-utils package." % repoquery) - + if params['list']: results = dict(results=list_stuff(params['conf_file'], params['list'])) module.exit_json(**results) - + else: pkg = params['pkg'] if 'pkg' is None: