From e3f5af377f669496ff7bd42c2c9a0d9ebc3332a6 Mon Sep 17 00:00:00 2001 From: Ruggero Marchei Date: Mon, 16 Jun 2014 15:06:50 +0200 Subject: [PATCH] move get_distribution_version() to basic.py --- lib/ansible/module_utils/basic.py | 12 ++++++++++++ library/system/hostname | 21 +++++---------------- 2 files changed, 17 insertions(+), 16 deletions(-) mode change 100644 => 100755 library/system/hostname diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 156aa480a07..ed3a1d74783 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -142,6 +142,18 @@ def get_distribution(): distribution = None return distribution +def get_distribution_version(): + ''' return the distribution version ''' + if platform.system() == 'Linux': + try: + distribution_version = platform.linux_distribution()[1] + except: + # FIXME: MethodMissing, I assume? + distribution_version = platform.dist()[1] + else: + distribution_version = None + return distribution_version + def load_platform_subclass(cls, *args, **kwargs): ''' used by modules like User to have different implementations based on detected platform. See User diff --git a/library/system/hostname b/library/system/hostname old mode 100644 new mode 100755 index 66d8d6c8159..775b47a1ff9 --- a/library/system/hostname +++ b/library/system/hostname @@ -39,20 +39,8 @@ EXAMPLES = ''' - hostname: name=web01 ''' -import platform - - -def get_distribution_version(): - ''' return the distribution version ''' - if platform.system() == 'Linux': - try: - distribution_version = platform.linux_distribution()[1] - except: - # FIXME: MethodMissing, I assume? - distribution_version = platform.dist()[1] - else: - distribution_version = None - return distribution_version +# import module snippets +from ansible.module_utils.basic import * class UnimplementedStrategy(object): @@ -283,6 +271,9 @@ class FedoraStrategy(GenericStrategy): self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" % (rc, out, err)) + +# =========================================== + class FedoraHostname(Hostname): platform = 'Linux' distribution = 'Fedora' @@ -380,6 +371,4 @@ def main(): module.exit_json(changed=changed, name=name) -# import module snippets -from ansible.module_utils.basic import * main()