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
9945a732
Commit
9945a732
authored
Aug 23, 2014
by
Johann Schmitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hostname strategy implementation for OpenRC based systems (e.g. Gentoo)
parent
f4d649be
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
library/system/hostname
+43
-0
No files found.
library/system/hostname
View file @
9945a732
...
@@ -288,6 +288,44 @@ class FedoraStrategy(GenericStrategy):
...
@@ -288,6 +288,44 @@ class FedoraStrategy(GenericStrategy):
# ===========================================
# ===========================================
class
OpenRCStrategy
(
GenericStrategy
):
"""
This is a Gentoo (OpenRC) Hostname manipulation strategy class - it edits
the /etc/conf.d/hostname file.
"""
HOSTNAME_FILE
=
'/etc/conf.d/hostname'
def
get_permanent_hostname
(
self
):
try
:
with
open
(
self
.
HOSTNAME_FILE
,
'r'
)
as
f
:
for
line
in
f
:
line
=
line
.
strip
()
if
line
.
startswith
(
'hostname='
):
return
line
[
10
:]
.
strip
(
'"'
)
return
None
except
Exception
,
err
:
self
.
module
.
fail_json
(
msg
=
"failed to read hostname:
%
s"
%
str
(
err
))
def
set_permanent_hostname
(
self
,
name
):
try
:
with
open
(
self
.
HOSTNAME_FILE
,
'r'
)
as
f
:
lines
=
[
x
.
strip
()
for
x
in
f
]
for
i
,
line
in
enumerate
(
lines
):
if
line
.
startswith
(
'hostname='
):
lines
[
i
]
=
'hostname="
%
s"'
%
name
break
with
open
(
self
.
HOSTNAME_FILE
,
'w'
)
as
f
:
f
.
write
(
'
\n
'
.
join
(
lines
)
+
'
\n
'
)
except
Exception
,
err
:
self
.
module
.
fail_json
(
msg
=
"failed to update hostname:
%
s"
%
str
(
err
))
# ===========================================
class
FedoraHostname
(
Hostname
):
class
FedoraHostname
(
Hostname
):
platform
=
'Linux'
platform
=
'Linux'
distribution
=
'Fedora'
distribution
=
'Fedora'
...
@@ -366,6 +404,11 @@ class LinaroHostname(Hostname):
...
@@ -366,6 +404,11 @@ class LinaroHostname(Hostname):
distribution
=
'Linaro'
distribution
=
'Linaro'
strategy_class
=
DebianStrategy
strategy_class
=
DebianStrategy
class
GentooHostname
(
Hostname
):
platform
=
'Linux'
distribution
=
'Gentoo base system'
strategy_class
=
OpenRCStrategy
# ===========================================
# ===========================================
def
main
():
def
main
():
...
...
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