Add Solaris support in hostname module

feature_pull_request: #1804
This commit is contained in:
saito-hideki 2015-07-25 23:32:55 +09:00
parent b991a2708b
commit e91ad2ab6c

View file

@ -21,7 +21,9 @@
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: hostname module: hostname
author: "Hiroaki Nakamura (@hnakamur)" author:
- "Hiroaki Nakamura (@hnakamur)"
- "Hideki Saito (@saito-hideki)"
version_added: "1.4" version_added: "1.4"
short_description: Manage hostname short_description: Manage hostname
requirements: [ hostname ] requirements: [ hostname ]
@ -116,13 +118,13 @@ class GenericStrategy(object):
- set_current_hostname(name) - set_current_hostname(name)
- set_permanent_hostname(name) - set_permanent_hostname(name)
""" """
def __init__(self, module): def __init__(self, module):
self.module = module self.module = module
self.hostname_cmd = self.module.get_bin_path('hostname', True)
HOSTNAME_CMD = '/bin/hostname'
def get_current_hostname(self): def get_current_hostname(self):
cmd = [self.HOSTNAME_CMD] cmd = [self.hostname_cmd]
rc, out, err = self.module.run_command(cmd) rc, out, err = self.module.run_command(cmd)
if rc != 0: if rc != 0:
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" %
@ -130,7 +132,7 @@ class GenericStrategy(object):
return out.strip() return out.strip()
def set_current_hostname(self, name): def set_current_hostname(self, name):
cmd = [self.HOSTNAME_CMD, name] cmd = [self.hostname_cmd, name]
rc, out, err = self.module.run_command(cmd) rc, out, err = self.module.run_command(cmd)
if rc != 0: if rc != 0:
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" %
@ -369,11 +371,9 @@ class SolarisStrategy(GenericStrategy):
execute hostname command. execute hostname command.
""" """
HOSTNAME_CMD = '/usr/bin/hostname'
def set_current_hostname(self, name): def set_current_hostname(self, name):
cmd_option = '-t' cmd_option = '-t'
cmd = [self.HOSTNAME_CMD, cmd_option, name] cmd = [self.hostname_cmd, cmd_option, name]
rc, out, err = self.module.run_command(cmd) rc, out, err = self.module.run_command(cmd)
if rc != 0: if rc != 0:
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" %
@ -390,7 +390,7 @@ class SolarisStrategy(GenericStrategy):
return out.strip() return out.strip()
def set_permanent_hostname(self, name): def set_permanent_hostname(self, name):
cmd = [self.HOSTNAME_CMD, name] cmd = [self.hostname_cmd, name]
rc, out, err = self.module.run_command(cmd) rc, out, err = self.module.run_command(cmd)
if rc != 0: if rc != 0:
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" %