Merge remote-tracking branch 'upstream/devel' into devel

reviewable/pr18780/r1
Philippe Makowski 11 years ago
commit 656cc5c7be

@ -392,9 +392,7 @@ def create_instances(module, ec2):
if group_name:
grp_details = ec2.get_all_security_groups()
if type(group_name) == list:
# FIXME: this should be a nice list comprehension
# also not py 2.4 compliant
group_id = list(filter(lambda grp: str(grp.id) if str(tmp) in str(grp) else None, grp_details) for tmp in group_name)
group_id = [ str(grp.id) for grp in grp_details if str(grp.name) in group_name ]
elif type(group_name) == str:
for grp in grp_details:
if str(group_name) in str(grp):

@ -136,6 +136,29 @@ PROTOCOLS = ['DNS_TCP', 'DNS_UDP', 'FTP', 'HTTP', 'HTTPS', 'IMAPS', 'IMAPv4',
'TCP_CLIENT_FIRST', 'UDP', 'UDP_STREAM', 'SFTP']
def to_dict(obj):
instance = {}
for key in dir(obj):
value = getattr(obj, key)
if key == 'virtual_ips':
instance[key] = []
for vip in value:
vip_dict = {}
for vip_key, vip_value in vars(vip).iteritems():
if isinstance(vip_value, NON_CALLABLES):
vip_dict[vip_key] = vip_value
instance[key].append(vip_dict)
elif key == 'nodes':
instance[key] = []
for node in value:
instance[key].append(node.to_dict())
elif (isinstance(value, NON_CALLABLES) and
not key.startswith('_')):
instance[key] = value
return instance
def cloud_load_balancer(module, state, name, meta, algorithm, port, protocol,
vip_type, timeout, wait, wait_timeout):
for arg in (state, name, port, protocol, vip_type):
@ -210,20 +233,7 @@ def cloud_load_balancer(module, state, name, meta, algorithm, port, protocol,
pyrax.utils.wait_for_build(balancer, interval=5, attempts=attempts)
balancer.get()
instance = {}
for key, value in vars(balancer).iteritems():
if key == 'virtual_ips':
virtual_ips = []
instance[key] = []
for vip in value:
vip_dict = {}
for vip_key, vip_value in vars(vip).iteritems():
if isinstance(vip_value, NON_CALLABLES):
vip_dict[vip_key] = vip_value
instance[key].append(vip_dict)
elif (isinstance(value, NON_CALLABLES) and
not key.startswith('_')):
instance[key] = value
instance = to_dict(balancer)
result = dict(changed=changed, balancer=instance)
@ -246,20 +256,7 @@ def cloud_load_balancer(module, state, name, meta, algorithm, port, protocol,
except Exception, e:
module.fail_json(msg='%s' % e.message)
instance = {}
for key, value in vars(balancer).iteritems():
if key == 'virtual_ips':
virtual_ips = []
instance[key] = []
for vip in value:
vip_dict = {}
for vip_key, vip_value in vars(vip).iteritems():
if isinstance(vip_value, NON_CALLABLES):
vip_dict[vip_key] = vip_value
instance[key].append(vip_dict)
elif (isinstance(value, NON_CALLABLES) and
not key.startswith('_')):
instance[key] = value
instance = to_dict(balancer)
if wait:
attempts = wait_timeout / 5

@ -24,8 +24,7 @@ DOCUMENTATION = '''
module: async_status
short_description: Obtain status of asynchronous task
description:
- "This module gets the status of an asynchronous task. See:
U(http://www.ansibleworks.com/docs/playbooks2.html#asynchronous-actions-and-polling)"
- "This module gets the status of an asynchronous task."
version_added: "0.5"
options:
jid:
@ -42,7 +41,7 @@ options:
choices: [ "status", "cleanup" ]
default: "status"
notes:
- See U(http://www.ansibleworks.com/docs/playbooks2.html#asynchronous-actions-and-polling)
- See also U(http://www.ansibleworks.com/docs/playbooks_async.html#asynchronous-actions-and-polling)
requirements: []
author: Michael DeHaan
'''

@ -36,7 +36,7 @@ description:
the target host, requests will be sent through that proxy. This
behaviour can be overridden by setting a variable for this task
(see `setting the environment
<http://www.ansibleworks.com/docs/playbooks2.html#setting-the-environment-and-working-with-proxies>`_),
<http://www.ansibleworks.com/docs/playbooks_environment.html#setting-the-environment-and-working-with-proxies>`_),
or by using the use_proxy option.
version_added: "0.6"
options:

@ -140,8 +140,8 @@ import fnmatch
# APT related constants
APT_ENVVARS = "DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical"
DPKG_OPTIONS = 'force-confdef,force-confold'
APT_GET_ZERO = "0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded."
APTITUDE_ZERO = "0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded."
APT_GET_ZERO = "0 upgraded, 0 newly installed"
APTITUDE_ZERO = "0 packages upgraded, 0 newly installed"
APT_LISTS_PATH = "/var/lib/apt/lists"
APT_UPDATE_SUCCESS_STAMP_PATH = "/var/lib/apt/periodic/update-success-stamp"
@ -256,9 +256,9 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None,
rc, out, err = m.run_command(cmd)
if rc:
m.fail_json(msg="'apt-get install %s' failed: %s" % (packages, err))
m.fail_json(msg="'apt-get install %s' failed: %s" % (packages, err), stdout=out, stderr=err)
else:
m.exit_json(changed=True)
m.exit_json(changed=True, stdout=out, stderr=err)
else:
m.exit_json(changed=False)
@ -285,8 +285,8 @@ def remove(m, pkgspec, cache, purge=False,
rc, out, err = m.run_command(cmd)
if rc:
m.fail_json(msg="'apt-get remove %s' failed: %s" % (packages, err))
m.exit_json(changed=True)
m.fail_json(msg="'apt-get remove %s' failed: %s" % (packages, err), stdout=out, stderr=err)
m.exit_json(changed=True, stdout=out, stderr=err)
def upgrade(m, mode="yes", force=False,
dpkg_options=expand_dpkg_options(DPKG_OPTIONS)):
@ -319,10 +319,10 @@ def upgrade(m, mode="yes", force=False,
force_yes, check_arg, upgrade_command)
rc, out, err = m.run_command(cmd)
if rc:
m.fail_json(msg="'%s %s' failed: %s" % (apt_cmd, upgrade_command, err))
m.fail_json(msg="'%s %s' failed: %s" % (apt_cmd, upgrade_command, err), stdout=out)
if (apt_cmd == APT_GET_CMD and APT_GET_ZERO in out) or (apt_cmd == APTITUDE_CMD and APTITUDE_ZERO in out):
m.exit_json(changed=False, msg=out)
m.exit_json(changed=True, msg=out)
m.exit_json(changed=False, msg=out, stdout=out, stderr=err)
m.exit_json(changed=True, msg=out, stdout=out, stderr=err)
def main():
module = AnsibleModule(
@ -344,7 +344,13 @@ def main():
)
if not HAS_PYTHON_APT:
module.fail_json(msg="Could not import python modules: apt, apt_pkg. Please install python-apt package.")
try:
module.run_command('apt-get install python-apt -y -q')
global apt, apt_pkg
import apt
import apt_pkg
except:
module.fail_json(msg="Could not import python modules: apt, apt_pkg. Please install python-apt package.")
global APTITUDE_CMD
APTITUDE_CMD = module.get_bin_path("aptitude", False)

@ -89,9 +89,10 @@ def remove_packages(module, pkgin_path, packages):
if not query_package(module, pkgin_path, package):
continue
rc, out, err = module.run_command("%s delete -y %s" % (pkgin_path, package))
if not module.check_mode:
rc, out, err = module.run_command("%s delete -y %s" % (pkgin_path, package))
if query_package(module, pkgin_path, package):
if not module.check_mode and query_package(module, pkgin_path, package):
module.fail_json(msg="failed to remove %s: %s" % (package, out))
remove_c += 1
@ -110,7 +111,7 @@ def install_packages(module, pkgin_path, packages, cached, pkgsite):
if pkgsite != "":
pkgsite="PACKAGESITE=%s" % (pkgsite)
if cached == "no":
if not module.check_mode and cached == "no":
rc, out, err = module.run_command("%s %s update" % (pkgsite, pkgin_path))
if rc != 0:
module.fail_json(msg="Could not update catalogue")
@ -119,9 +120,10 @@ def install_packages(module, pkgin_path, packages, cached, pkgsite):
if query_package(module, pkgin_path, package):
continue
rc, out, err = module.run_command("%s %s install -U -y %s" % (pkgsite, pkgin_path, package))
if not module.check_mode:
rc, out, err = module.run_command("%s %s install -U -y %s" % (pkgsite, pkgin_path, package))
if not query_package(module, pkgin_path, package):
if not module.check_mode and query_package(module, pkgin_path, package):
module.fail_json(msg="failed to install %s: %s" % (package, out))
install_c += 1
@ -134,11 +136,12 @@ def install_packages(module, pkgin_path, packages, cached, pkgsite):
def main():
module = AnsibleModule(
argument_spec = dict(
state = dict(default="present", choices=["present","absent"]),
name = dict(aliases=["pkg"], required=True),
cached = dict(default="no", required=False, choices=["yes","no"]),
pkgsite = dict(default="", required=False)))
argument_spec = dict(
state = dict(default="present", choices=["present","absent"]),
name = dict(aliases=["pkg"], required=True),
cached = dict(default=False, type='bool'),
pkgsite = dict(default="", required=False)),
supports_check_mode = True)
pkgin_path = module.get_bin_path('pkg', True)

@ -428,6 +428,8 @@ def main():
changed = False
res_args = dict()
# Ensure all files generated are only writable by the owning user. Primarily relevant for the cron_file option.
os.umask(022)
crontab = CronTab(module, user, cron_file)
if crontab.syslogging:

@ -790,9 +790,11 @@ class FreeBsdService(Service):
self.rcconf_file = rcfile
rc, stdout, stderr = self.execute_command("%s %s %s %s" % (self.svc_cmd, self.name, 'rcvar', self.arguments))
cmd = "%s %s %s %s" % (self.svc_cmd, self.name, 'rcvar', self.arguments)
rcvars = shlex.split(stdout, comments=True)
if not rcvars:
self.module.fail_json(msg="unable to determine rcvar")
self.module.fail_json(msg="unable to determine rcvar", stdout=stdout, stderr=stderr)
# In rare cases, i.e. sendmail, rcvar can return several key=value pairs
# Usually there is just one, however. In other rare cases, i.e. uwsgi,
@ -805,7 +807,7 @@ class FreeBsdService(Service):
break
if self.rcconf_key is None:
self.module.fail_json(msg="unable to determine rcvar")
self.module.fail_json(msg="unable to determine rcvar", stdout=stdout, stderr=stderr)
return self.service_enable_rcconf()

Loading…
Cancel
Save