Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
54243dc8
Commit
54243dc8
authored
Oct 16, 2013
by
Hiroaki Nakamura
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for Fedora, OpenSUSE and ArchLinux.
Tested under Fedora 19 and OpenSUSE 12.3. Not tested on ArchLinux.
parent
8c5eb96d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
library/system/hostname
+58
-0
No files found.
library/system/hostname
View file @
54243dc8
...
...
@@ -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
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment