Add support for Fedora, OpenSUSE and ArchLinux.
Tested under Fedora 19 and OpenSUSE 12.3. Not tested on ArchLinux.
This commit is contained in:
parent
8c5eb96de4
commit
54243dc8f5
1 changed files with 58 additions and 0 deletions
|
@ -233,6 +233,64 @@ class CentOSHostname(Hostname):
|
|||
|
||||
# ===========================================
|
||||
|
||||
class FedoraStrategy(GenericStrategy):
|
||||
"""
|
||||
This is a Fedora family Hostname manipulation strategy class - it uses
|
||||
the hostnamectl command.
|
||||
"""
|
||||
|
||||
def get_current_hostname(self):
|
||||
cmd = ['hostname']
|
||||
rc, out, err = self.module.run_command(cmd)
|
||||
if rc != 0:
|
||||
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
||||
(rc, out, err))
|
||||
return out.strip()
|
||||
|
||||
def set_current_hostname(self, name):
|
||||
cmd = ['hostnamectl', '--transient', 'set-hostname', name]
|
||||
rc, out, err = self.module.run_command(cmd)
|
||||
if rc != 0:
|
||||
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
||||
(rc, out, err))
|
||||
|
||||
def get_permanent_hostname(self):
|
||||
cmd = 'hostnamectl status | awk \'/^ *Static hostname:/{printf("%s", $3)}\''
|
||||
rc, out, err = self.module.run_command(cmd)
|
||||
if rc != 0:
|
||||
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
||||
(rc, out, err))
|
||||
return out
|
||||
|
||||
def set_permanent_hostname(self, name):
|
||||
cmd = ['hostnamectl', '--pretty', 'set-hostname', name]
|
||||
rc, out, err = self.module.run_command(cmd)
|
||||
if rc != 0:
|
||||
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
||||
(rc, out, err))
|
||||
cmd = ['hostnamectl', '--static', 'set-hostname', name]
|
||||
rc, out, err = self.module.run_command(cmd)
|
||||
if rc != 0:
|
||||
self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" %
|
||||
(rc, out, err))
|
||||
|
||||
class FedoraHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Fedora'
|
||||
strategy_class = FedoraStrategy
|
||||
|
||||
class OpenSUSEHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Opensuse '
|
||||
strategy_class = FedoraStrategy
|
||||
|
||||
class ArchHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Arch'
|
||||
strategy_class = FedoraStrategy
|
||||
|
||||
# ===========================================
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
|
|
Loading…
Reference in a new issue