Merge branch '7763' of https://github.com/rmarchei/ansible into rmarchei-7763
This commit is contained in:
commit
3529b1cb33
2 changed files with 77 additions and 45 deletions
|
@ -142,6 +142,18 @@ def get_distribution():
|
||||||
distribution = None
|
distribution = None
|
||||||
return distribution
|
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):
|
def load_platform_subclass(cls, *args, **kwargs):
|
||||||
'''
|
'''
|
||||||
used by modules like User to have different implementations based on detected platform. See User
|
used by modules like User to have different implementations based on detected platform. See User
|
||||||
|
|
110
library/system/hostname
Normal file → Executable file
110
library/system/hostname
Normal file → Executable file
|
@ -39,6 +39,10 @@ EXAMPLES = '''
|
||||||
- hostname: name=web01
|
- hostname: name=web01
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
# import module snippets
|
||||||
|
from ansible.module_utils.basic import *
|
||||||
|
|
||||||
|
|
||||||
class UnimplementedStrategy(object):
|
class UnimplementedStrategy(object):
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
|
@ -135,6 +139,7 @@ class GenericStrategy(object):
|
||||||
def set_permanent_hostname(self, name):
|
def set_permanent_hostname(self, name):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
||||||
class DebianStrategy(GenericStrategy):
|
class DebianStrategy(GenericStrategy):
|
||||||
|
@ -173,20 +178,6 @@ class DebianStrategy(GenericStrategy):
|
||||||
self.module.fail_json(msg="failed to update hostname: %s" %
|
self.module.fail_json(msg="failed to update hostname: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
|
|
||||||
class DebianHostname(Hostname):
|
|
||||||
platform = 'Linux'
|
|
||||||
distribution = 'Debian'
|
|
||||||
strategy_class = DebianStrategy
|
|
||||||
|
|
||||||
class UbuntuHostname(Hostname):
|
|
||||||
platform = 'Linux'
|
|
||||||
distribution = 'Ubuntu'
|
|
||||||
strategy_class = DebianStrategy
|
|
||||||
|
|
||||||
class LinaroHostname(Hostname):
|
|
||||||
platform = 'Linux'
|
|
||||||
distribution = 'Linaro'
|
|
||||||
strategy_class = DebianStrategy
|
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
||||||
|
@ -236,35 +227,6 @@ class RedHatStrategy(GenericStrategy):
|
||||||
self.module.fail_json(msg="failed to update hostname: %s" %
|
self.module.fail_json(msg="failed to update hostname: %s" %
|
||||||
str(err))
|
str(err))
|
||||||
|
|
||||||
class RedHat5Hostname(Hostname):
|
|
||||||
platform = 'Linux'
|
|
||||||
distribution = 'Redhat'
|
|
||||||
strategy_class = RedHatStrategy
|
|
||||||
|
|
||||||
class RedHatServerHostname(Hostname):
|
|
||||||
platform = 'Linux'
|
|
||||||
distribution = 'Red hat enterprise linux server'
|
|
||||||
strategy_class = RedHatStrategy
|
|
||||||
|
|
||||||
class RedHatWorkstationHostname(Hostname):
|
|
||||||
platform = 'Linux'
|
|
||||||
distribution = 'Red hat enterprise linux workstation'
|
|
||||||
strategy_class = RedHatStrategy
|
|
||||||
|
|
||||||
class CentOSHostname(Hostname):
|
|
||||||
platform = 'Linux'
|
|
||||||
distribution = 'Centos'
|
|
||||||
strategy_class = RedHatStrategy
|
|
||||||
|
|
||||||
class AmazonLinuxHostname(Hostname):
|
|
||||||
platform = 'Linux'
|
|
||||||
distribution = 'Amazon'
|
|
||||||
strategy_class = RedHatStrategy
|
|
||||||
|
|
||||||
class ScientificLinuxHostname(Hostname):
|
|
||||||
platform = 'Linux'
|
|
||||||
distribution = 'Scientific'
|
|
||||||
strategy_class = RedHatStrategy
|
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
||||||
|
@ -309,6 +271,9 @@ class FedoraStrategy(GenericStrategy):
|
||||||
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
||||||
(rc, out, err))
|
(rc, out, err))
|
||||||
|
|
||||||
|
|
||||||
|
# ===========================================
|
||||||
|
|
||||||
class FedoraHostname(Hostname):
|
class FedoraHostname(Hostname):
|
||||||
platform = 'Linux'
|
platform = 'Linux'
|
||||||
distribution = 'Fedora'
|
distribution = 'Fedora'
|
||||||
|
@ -324,6 +289,63 @@ class ArchHostname(Hostname):
|
||||||
distribution = 'Arch'
|
distribution = 'Arch'
|
||||||
strategy_class = FedoraStrategy
|
strategy_class = FedoraStrategy
|
||||||
|
|
||||||
|
class RedHat5Hostname(Hostname):
|
||||||
|
platform = 'Linux'
|
||||||
|
distribution = 'Redhat'
|
||||||
|
strategy_class = RedHatStrategy
|
||||||
|
|
||||||
|
class RedHatServerHostname(Hostname):
|
||||||
|
platform = 'Linux'
|
||||||
|
distribution = 'Red hat enterprise linux server'
|
||||||
|
if float(get_distribution_version()) >= 7:
|
||||||
|
strategy_class = FedoraStrategy
|
||||||
|
else:
|
||||||
|
strategy_class = RedHatStrategy
|
||||||
|
|
||||||
|
class RedHatWorkstationHostname(Hostname):
|
||||||
|
platform = 'Linux'
|
||||||
|
distribution = 'Red hat enterprise linux workstation'
|
||||||
|
if float(get_distribution_version()) >= 7:
|
||||||
|
strategy_class = FedoraStrategy
|
||||||
|
else:
|
||||||
|
strategy_class = RedHatStrategy
|
||||||
|
|
||||||
|
class CentOSHostname(Hostname):
|
||||||
|
platform = 'Linux'
|
||||||
|
distribution = 'Centos'
|
||||||
|
if float(get_distribution_version()) >= 7:
|
||||||
|
strategy_class = FedoraStrategy
|
||||||
|
else:
|
||||||
|
strategy_class = RedHatStrategy
|
||||||
|
|
||||||
|
class ScientificLinuxHostname(Hostname):
|
||||||
|
platform = 'Linux'
|
||||||
|
distribution = 'Scientific'
|
||||||
|
if float(get_distribution_version()) >= 7:
|
||||||
|
strategy_class = FedoraStrategy
|
||||||
|
else:
|
||||||
|
strategy_class = RedHatStrategy
|
||||||
|
|
||||||
|
class AmazonLinuxHostname(Hostname):
|
||||||
|
platform = 'Linux'
|
||||||
|
distribution = 'Amazon'
|
||||||
|
strategy_class = RedHatStrategy
|
||||||
|
|
||||||
|
class DebianHostname(Hostname):
|
||||||
|
platform = 'Linux'
|
||||||
|
distribution = 'Debian'
|
||||||
|
strategy_class = DebianStrategy
|
||||||
|
|
||||||
|
class UbuntuHostname(Hostname):
|
||||||
|
platform = 'Linux'
|
||||||
|
distribution = 'Ubuntu'
|
||||||
|
strategy_class = DebianStrategy
|
||||||
|
|
||||||
|
class LinaroHostname(Hostname):
|
||||||
|
platform = 'Linux'
|
||||||
|
distribution = 'Linaro'
|
||||||
|
strategy_class = DebianStrategy
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -349,6 +371,4 @@ def main():
|
||||||
|
|
||||||
module.exit_json(changed=changed, name=name)
|
module.exit_json(changed=changed, name=name)
|
||||||
|
|
||||||
# import module snippets
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue