From 20ef2696bcfa2b2ed68b75d4f79b4f88f49216aa Mon Sep 17 00:00:00 2001 From: Alexander Gubin Date: Wed, 26 Nov 2014 11:27:29 +0100 Subject: [PATCH 01/18] Fix lvol: Find LVM commands in PATH env --- system/lvol.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/system/lvol.py b/system/lvol.py index 96f1b846e27..e9d477edf86 100644 --- a/system/lvol.py +++ b/system/lvol.py @@ -152,8 +152,9 @@ def main(): else: unit = size_unit + lvs_cmd = module.get_bin_path("lvs", required=True) rc, current_lvs, err = module.run_command( - "lvs --noheadings -o lv_name,size --units %s --separator ';' %s" % (unit, vg)) + "%s --noheadings -o lv_name,size --units %s --separator ';' %s" % (lvs_cmd, unit, vg)) if rc != 0: if state == 'absent': @@ -185,7 +186,8 @@ def main(): if module.check_mode: changed = True else: - rc, _, err = module.run_command("lvcreate -n %s -%s %s%s %s" % (lv, size_opt, size, size_unit, vg)) + lvcreate_cmd = module.get_bin_path("lvcreate", required=True) + rc, _, err = module.run_command("%s -n %s -%s %s%s %s" % (lvcreate_cmd, lv, size_opt, size, size_unit, vg)) if rc == 0: changed = True else: @@ -197,7 +199,8 @@ def main(): module.exit_json(changed=True) if not force: module.fail_json(msg="Sorry, no removal of logical volume %s without force=yes." % (this_lv['name'])) - rc, _, err = module.run_command("lvremove --force %s/%s" % (vg, this_lv['name'])) + lvremove_cmd = module.get_bin_path("lvremove", required=True) + rc, _, err = module.run_command("%s --force %s/%s" % (lvremove_cmd, vg, this_lv['name'])) if rc == 0: module.exit_json(changed=True) else: @@ -209,11 +212,12 @@ def main(): ### resize LV tool = None if size > this_lv['size']: - tool = 'lvextend' + tool = module.get_bin_path("lvextend", required=True) elif size < this_lv['size']: if not force: module.fail_json(msg="Sorry, no shrinking of %s without force=yes." % (this_lv['name'])) - tool = 'lvreduce --force' + tool = module.get_bin_path("lvextend", required=True) + tool.append("--force") if tool: if module.check_mode: From c4986bf78d7e7ab96527c4d64546584bbff83e40 Mon Sep 17 00:00:00 2001 From: Stanislav Antic Date: Mon, 5 Jan 2015 14:46:27 +0100 Subject: [PATCH 02/18] Fixes #155 --- database/mysql/mysql_replication.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/database/mysql/mysql_replication.py b/database/mysql/mysql_replication.py index b93150a43b5..f75d6a05b5d 100644 --- a/database/mysql/mysql_replication.py +++ b/database/mysql/mysql_replication.py @@ -235,12 +235,12 @@ def main(): master_host=dict(default=None), master_user=dict(default=None), master_password=dict(default=None), - master_port=dict(default=None), - master_connect_retry=dict(default=None), + master_port=dict(default=None, type='int'), + master_connect_retry=dict(default=None, type='int'), master_log_file=dict(default=None), - master_log_pos=dict(default=None), + master_log_pos=dict(default=None, type='int'), relay_log_file=dict(default=None), - relay_log_pos=dict(default=None), + relay_log_pos=dict(default=None, type='int'), master_ssl=dict(default=False, type='bool'), master_ssl_ca=dict(default=None), master_ssl_capath=dict(default=None), From d4f5b6d41a707f0f89d79882ac2e68864935184f Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 5 Jan 2015 08:40:57 -0800 Subject: [PATCH 03/18] Fixes for docs building --- system/gluster_volume.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/gluster_volume.py b/system/gluster_volume.py index 087a4a0f6de..00e2cdeba65 100644 --- a/system/gluster_volume.py +++ b/system/gluster_volume.py @@ -24,6 +24,7 @@ module: gluster_volume short_description: Manage GlusterFS volumes description: - Create, remove, start, stop and tune GlusterFS volumes +version_added: "1.9" options: name: required: true @@ -34,7 +35,7 @@ options: choices: [ 'present', 'absent', 'started', 'stopped' ] description: - Use present/absent ensure if a volume exists or not, - use started/stopped to control it's availability. + use started/stopped to control it's availability. cluster: required: false description: From 3981872375debccb3798a0ee2fc886f3b86fbb72 Mon Sep 17 00:00:00 2001 From: Bert Mertens Date: Tue, 6 Jan 2015 09:57:30 +0100 Subject: [PATCH 04/18] Fix getent behaviour with fail_key=False --- system/getent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/getent.py b/system/getent.py index 7da1be45fae..bb6d162398c 100644 --- a/system/getent.py +++ b/system/getent.py @@ -86,7 +86,7 @@ def main(): database = dict(required=True), key = dict(required=False, default=None), split = dict(required=False, default=None), - fail_key = dict(required=False, default=True), + fail_key = dict(required=False, type='bool', default=True), ), supports_check_mode = True, ) From a32869d492f5e2adbfda4a132d565c8219d18890 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 7 Jan 2015 09:20:45 -0800 Subject: [PATCH 05/18] Allow 0 to be specified --- database/mysql/mysql_replication.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/database/mysql/mysql_replication.py b/database/mysql/mysql_replication.py index f75d6a05b5d..70e226a6f5b 100644 --- a/database/mysql/mysql_replication.py +++ b/database/mysql/mysql_replication.py @@ -317,7 +317,6 @@ def main(): module.fail_json(msg="Server is not configured as mysql slave") elif mode in "changemaster": - print "Change master" chm=[] chm_params = {} if master_host: @@ -329,22 +328,22 @@ def main(): if master_password: chm.append("MASTER_PASSWORD=%(master_password)s") chm_params['master_password'] = master_password - if master_port: + if master_port is not None: chm.append("MASTER_PORT=%(master_port)s") chm_params['master_port'] = master_port - if master_connect_retry: + if master_connect_retry is not None: chm.append("MASTER_CONNECT_RETRY=%(master_connect_retry)s") chm_params['master_connect_retry'] = master_connect_retry if master_log_file: chm.append("MASTER_LOG_FILE=%(master_log_file)s") chm_params['master_log_file'] = master_log_file - if master_log_pos: + if master_log_pos is not None: chm.append("MASTER_LOG_POS=%(master_log_pos)s") chm_params['master_log_pos'] = master_log_pos if relay_log_file: chm.append("RELAY_LOG_FILE=%(relay_log_file)s") chm_params['relay_log_file'] = relay_log_file - if relay_log_pos: + if relay_log_pos is not None: chm.append("RELAY_LOG_POS=%(relay_log_pos)s") chm_params['relay_log_pos'] = relay_log_pos if master_ssl: From 7248c0861da31c3c6e0155c9df478cc0b4a22804 Mon Sep 17 00:00:00 2001 From: Justin Lecher Date: Fri, 9 Jan 2015 16:07:42 +0100 Subject: [PATCH 06/18] Allow disabling of autorefresh for zypper repositories In case of release repositories or other special cases you might not need the autorefreshing of the repos. This patch adds a configure option instead of hard enabling this. Signed-off-by: Justin Lecher --- packaging/os/zypper_repository.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packaging/os/zypper_repository.py b/packaging/os/zypper_repository.py index 5e41683734b..44a0ed6029c 100644 --- a/packaging/os/zypper_repository.py +++ b/packaging/os/zypper_repository.py @@ -2,6 +2,7 @@ # encoding: utf-8 # (c) 2013, Matthias Vogelgesang +# (c) 2014, Justin Lecher # # This file is part of Ansible # @@ -58,6 +59,13 @@ options: default: "no" choices: [ "yes", "no" ] aliases: [] + refresh: + description: + - Enable autorefresh of the repository. + required: false + default: "no" + choices: [ "yes", "no" ] + aliases: [] notes: [] requirements: [ zypper ] ''' @@ -145,11 +153,11 @@ def repo_exists(module, old_zypper, **kwargs): return False -def add_repo(module, repo, alias, description, disable_gpg_check, old_zypper): +def add_repo(module, repo, alias, description, disable_gpg_check, old_zypper, refresh): if old_zypper: cmd = ['/usr/bin/zypper', 'sa'] else: - cmd = ['/usr/bin/zypper', 'ar', '--check', '--refresh'] + cmd = ['/usr/bin/zypper', 'ar', '--check'] if repo.startswith("file:/") and old_zypper: cmd.extend(['-t', 'Plaindir']) @@ -162,6 +170,9 @@ def add_repo(module, repo, alias, description, disable_gpg_check, old_zypper): if disable_gpg_check and not old_zypper: cmd.append('--no-gpgcheck') + if refresh: + cmd.append('--refresh') + cmd.append(repo) if not repo.endswith('.repo'): @@ -216,6 +227,7 @@ def main(): state=dict(choices=['present', 'absent'], default='present'), description=dict(required=False), disable_gpg_check = dict(required=False, default='no', type='bool'), + refresh = dict(required=False, default='yes', type='bool'), ), supports_check_mode=False, ) @@ -225,6 +237,7 @@ def main(): name = module.params['name'] description = module.params['description'] disable_gpg_check = module.params['disable_gpg_check'] + refresh = module.params['refresh'] def exit_unchanged(): module.exit_json(changed=False, repo=repo, state=state, name=name) @@ -260,7 +273,7 @@ def main(): if exists: exit_unchanged() - changed = add_repo(module, repo, name, description, disable_gpg_check, old_zypper) + changed = add_repo(module, repo, name, description, disable_gpg_check, old_zypper, refresh) elif state == 'absent': if not exists: exit_unchanged() From 25f595c2bada725e3b8d82a69e6fb0b680ff34f9 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Mon, 12 Jan 2015 18:52:25 +0100 Subject: [PATCH 07/18] Avoid to use the builtin 'echo' By default, the interpretation of escape characters could be disabled (bash) or enabled (dash). --- system/debconf.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/system/debconf.py b/system/debconf.py index 592c2c865c7..b5af4744d56 100644 --- a/system/debconf.py +++ b/system/debconf.py @@ -86,8 +86,6 @@ debconf: name='oracle-java7-installer' question='shared/accepted-oracle-license- debconf: name='tzdata' ''' -import pipes - def get_selections(module, pkg): cmd = [module.get_bin_path('debconf-show', True), pkg] rc, out, err = module.run_command(' '.join(cmd)) @@ -106,14 +104,14 @@ def get_selections(module, pkg): def set_selection(module, pkg, question, vtype, value, unseen): - data = ' '.join([ question, vtype, value ]) - setsel = module.get_bin_path('debconf-set-selections', True) - cmd = ["echo %s %s |" % (pipes.quote(pkg), pipes.quote(data)), setsel] + cmd = [setsel] if unseen: cmd.append('-u') - return module.run_command(' '.join(cmd), use_unsafe_shell=True) + data = ' '.join([pkg, question, vtype, value]) + + return module.run_command(cmd, data=data) def main(): From 40298a8f2422ab230b23f49e841855d6039dd1a8 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Mon, 12 Jan 2015 19:02:30 +0100 Subject: [PATCH 08/18] remove unused variable --- system/debconf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/system/debconf.py b/system/debconf.py index b5af4744d56..0deaff25eb1 100644 --- a/system/debconf.py +++ b/system/debconf.py @@ -135,7 +135,6 @@ def main(): unseen = module.params["unseen"] prev = get_selections(module, pkg) - diff = '' changed = False msg = "" From 8658b6783a7c2e8d292ac170eb636662bd01bee3 Mon Sep 17 00:00:00 2001 From: Justin Lecher Date: Wed, 14 Jan 2015 15:50:18 +0100 Subject: [PATCH 09/18] Keep default behaviour for refresh Signed-off-by: Justin Lecher --- packaging/os/zypper_repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/os/zypper_repository.py b/packaging/os/zypper_repository.py index 44a0ed6029c..9cdce3ee4f3 100644 --- a/packaging/os/zypper_repository.py +++ b/packaging/os/zypper_repository.py @@ -63,7 +63,7 @@ options: description: - Enable autorefresh of the repository. required: false - default: "no" + default: "yes" choices: [ "yes", "no" ] aliases: [] notes: [] From 16d622aab833f3cb75a7253325dee181a009621c Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 14 Jan 2015 20:49:44 -0800 Subject: [PATCH 10/18] Fix documentation in zypper_repository --- packaging/os/zypper_repository.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packaging/os/zypper_repository.py b/packaging/os/zypper_repository.py index 9cdce3ee4f3..f208305fe60 100644 --- a/packaging/os/zypper_repository.py +++ b/packaging/os/zypper_repository.py @@ -52,16 +52,16 @@ options: - A description of the repository disable_gpg_check: description: - - Whether to disable GPG signature checking of - all packages. Has an effect only if state is - I(present). + - Whether to disable GPG signature checking of + all packages. Has an effect only if state is + I(present). required: false default: "no" choices: [ "yes", "no" ] aliases: [] refresh: - description: - - Enable autorefresh of the repository. + description: + - Enable autorefresh of the repository. required: false default: "yes" choices: [ "yes", "no" ] From e529279feaf98bb9fc09c4deed2ec6df962704f8 Mon Sep 17 00:00:00 2001 From: Jens Carl Date: Thu, 15 Jan 2015 16:15:17 +0000 Subject: [PATCH 11/18] Fix typo Fix typo and remove an obsolete space. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d9c47f8303..7959fffa7cf 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ All new modules should be submitted here, and have a chance to be promoted to co Reporting bugs ============== -Take care to submit tickets to the appropriate repo where modules are contained. The repo is mentioned at the bottom of modlue documentation page at [docs.ansible.com](http://docs.ansible.com/). +Take care to submit tickets to the appropriate repo where modules are contained. The repo is mentioned at the bottom of module documentation page at [docs.ansible.com](http://docs.ansible.com/). Testing modules =============== @@ -18,4 +18,4 @@ Ansible [module development guide](http://docs.ansible.com/developing_modules.ht License ======= -As with Ansible, modules distributed with Ansible are GPLv3 licensed. User generated modules not part of this project can be of any license. +As with Ansible, modules distributed with Ansible are GPLv3 licensed. User generated modules not part of this project can be of any license. From 3795ab0379000f793ec3e82e57d81756ee37206e Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Fri, 24 Oct 2014 13:41:29 +0200 Subject: [PATCH 12/18] Clear rabbitmq_user pw when none is specified --- messaging/rabbitmq_user.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/messaging/rabbitmq_user.py b/messaging/rabbitmq_user.py index 1cbee360dff..b19ec1fc097 100644 --- a/messaging/rabbitmq_user.py +++ b/messaging/rabbitmq_user.py @@ -162,7 +162,11 @@ class RabbitMqUser(object): return dict() def add(self): - self._exec(['add_user', self.username, self.password]) + if self.password is not None: + self._exec(['add_user', self.username, self.password]) + else + self._exec(['add_user', self.username, '']) + self._exec(['clear_password', self.username]) def delete(self): self._exec(['delete_user', self.username]) From 2396f36f1192ba47723735f563972ac1bf695079 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 19 Jan 2015 09:40:04 -0800 Subject: [PATCH 13/18] Fix typo causing SyntaxError (missing colon) --- messaging/rabbitmq_user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging/rabbitmq_user.py b/messaging/rabbitmq_user.py index b19ec1fc097..f494ce802d9 100644 --- a/messaging/rabbitmq_user.py +++ b/messaging/rabbitmq_user.py @@ -164,7 +164,7 @@ class RabbitMqUser(object): def add(self): if self.password is not None: self._exec(['add_user', self.username, self.password]) - else + else: self._exec(['add_user', self.username, '']) self._exec(['clear_password', self.username]) From 5ae3bbaf05f5b08e688c0290a0103bf0dd94c421 Mon Sep 17 00:00:00 2001 From: Giovanni Tirloni Date: Tue, 20 Jan 2015 12:35:13 -0500 Subject: [PATCH 14/18] Fix dangerous use of empty list as default arg (mutable) --- monitoring/nagios.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/monitoring/nagios.py b/monitoring/nagios.py index 9219766b86a..c564e712b04 100644 --- a/monitoring/nagios.py +++ b/monitoring/nagios.py @@ -364,7 +364,7 @@ class Nagios(object): return notif_str - def schedule_svc_downtime(self, host, services=[], minutes=30): + def schedule_svc_downtime(self, host, services=None, minutes=30): """ This command is used to schedule downtime for a particular service. @@ -378,6 +378,10 @@ class Nagios(object): """ cmd = "SCHEDULE_SVC_DOWNTIME" + + if services is None: + services = [] + for service in services: dt_cmd_str = self._fmt_dt_str(cmd, host, minutes, svc=service) self._write_command(dt_cmd_str) @@ -518,7 +522,7 @@ class Nagios(object): notif_str = self._fmt_notif_str(cmd, host) self._write_command(notif_str) - def disable_svc_notifications(self, host, services=[]): + def disable_svc_notifications(self, host, services=None): """ This command is used to prevent notifications from being sent out for the specified service. @@ -530,6 +534,10 @@ class Nagios(object): """ cmd = "DISABLE_SVC_NOTIFICATIONS" + + if services is None: + services = [] + for service in services: notif_str = self._fmt_notif_str(cmd, host, svc=service) self._write_command(notif_str) @@ -628,7 +636,7 @@ class Nagios(object): else: return "Fail: could not write to the command file" - def enable_svc_notifications(self, host, services=[]): + def enable_svc_notifications(self, host, services=None): """ Enables notifications for a particular service. @@ -638,6 +646,10 @@ class Nagios(object): """ cmd = "ENABLE_SVC_NOTIFICATIONS" + + if services is None: + services = [] + nagios_return = True return_str_list = [] for service in services: From 42f79478a798f4b1d8eed2a1666e5727fb362747 Mon Sep 17 00:00:00 2001 From: Hiroshi Umehara Date: Wed, 21 Jan 2015 16:10:12 +0900 Subject: [PATCH 15/18] Add EUC-JP locale name normalization The function normalizes checks for UTF-8, but the same issue exists for other locales as well. This fix adds normalization for EUC-JP, a Japanese locale. --- system/locale_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/locale_gen.py b/system/locale_gen.py index 9ff0a87f36a..edf637fecb8 100644 --- a/system/locale_gen.py +++ b/system/locale_gen.py @@ -44,7 +44,7 @@ def is_present(name): def fix_case(name): """locale -a might return the encoding in either lower or upper case. Passing through this function makes them uniform for comparisons.""" - return name.replace(".utf8", ".UTF-8") + return name.replace(".utf8", ".UTF-8").replace(".eucjp", ".EUC-JP") def replace_line(existing_line, new_line): """Replaces lines in /etc/locale.gen""" From 0f4502982728af13e5b1ba12b470d2c76d776972 Mon Sep 17 00:00:00 2001 From: Rob White Date: Thu, 22 Jan 2015 11:01:33 +1100 Subject: [PATCH 16/18] Changed status() to be case-sensitive of process --- monitoring/monit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitoring/monit.py b/monitoring/monit.py index 558f1e696f2..b1c1b9453cd 100644 --- a/monitoring/monit.py +++ b/monitoring/monit.py @@ -75,8 +75,8 @@ def main(): # Sample output lines: # Process 'name' Running # Process 'name' Running - restart pending - parts = line.lower().split() - if len(parts) > 2 and parts[0] == 'process' and parts[1] == "'%s'" % name: + parts = line.split() + if len(parts) > 2 and parts[0] == 'Process' and parts[1] == "'%s'" % name: return ' '.join(parts[2:]) else: return '' From 13285765a8a41381e214d171813fc715b6cc728d Mon Sep 17 00:00:00 2001 From: Rob White Date: Thu, 22 Jan 2015 11:26:00 +1100 Subject: [PATCH 17/18] Keep 'process' lowercase to protect against upstream changes --- monitoring/monit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitoring/monit.py b/monitoring/monit.py index b1c1b9453cd..8772d22b2d8 100644 --- a/monitoring/monit.py +++ b/monitoring/monit.py @@ -76,7 +76,7 @@ def main(): # Process 'name' Running # Process 'name' Running - restart pending parts = line.split() - if len(parts) > 2 and parts[0] == 'Process' and parts[1] == "'%s'" % name: + if len(parts) > 2 and parts[0].lower() == 'process' and parts[1] == "'%s'" % name: return ' '.join(parts[2:]) else: return '' From 759e03247301ad47b537a91dbd60701919fa1f68 Mon Sep 17 00:00:00 2001 From: Hiroshi Umehara Date: Thu, 22 Jan 2015 12:07:10 +0900 Subject: [PATCH 18/18] Generalize locale name normalization --- system/locale_gen.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/system/locale_gen.py b/system/locale_gen.py index edf637fecb8..a9a17e38ab1 100644 --- a/system/locale_gen.py +++ b/system/locale_gen.py @@ -32,6 +32,11 @@ EXAMPLES = ''' - locale_gen: name=de_CH.UTF-8 state=present ''' +LOCALE_NORMALIZATION = { + ".utf8": ".UTF-8", + ".eucjp": ".EUC-JP", +} + # =========================================== # location module specific support methods. # @@ -44,7 +49,9 @@ def is_present(name): def fix_case(name): """locale -a might return the encoding in either lower or upper case. Passing through this function makes them uniform for comparisons.""" - return name.replace(".utf8", ".UTF-8").replace(".eucjp", ".EUC-JP") + for s, r in LOCALE_NORMALIZATION.iteritems(): + name = name.replace(s, r) + return name def replace_line(existing_line, new_line): """Replaces lines in /etc/locale.gen"""