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