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
4f91238e
Commit
4f91238e
authored
Aug 25, 2013
by
Hiroaki Nakamura
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite with "try ... finally" instead of "with" statement to support Python 2.4.
parent
3b1d7d88
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
5 deletions
+20
-5
library/system/hostname
+20
-5
No files found.
library/system/hostname
View file @
4f91238e
...
...
@@ -145,16 +145,22 @@ class DebianStrategy(GenericStrategy):
def
get_permanent_hostname
(
self
):
try
:
with
open
(
self
.
HOSTNAME_FILE
)
as
f
:
f
=
open
(
self
.
HOSTNAME_FILE
)
try
:
return
f
.
read
()
.
split
()
finally
:
f
.
close
()
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
,
'w+'
)
as
f
:
f
=
open
(
self
.
HOSTNAME_FILE
,
'w+'
)
try
:
f
.
write
(
"
%
s
\n
"
%
name
)
finally
:
f
.
close
()
except
Exception
,
err
:
self
.
module
.
fail_json
(
msg
=
"failed to update hostname:
%
s"
%
str
(
err
))
...
...
@@ -180,11 +186,14 @@ class RedHatStrategy(GenericStrategy):
def
get_permanent_hostname
(
self
):
try
:
with
open
(
self
.
NETWORK_FILE
,
'rb'
)
as
f
:
f
=
open
(
self
.
NETWORK_FILE
,
'rb'
)
try
:
for
line
in
f
.
readlines
():
if
line
.
startswith
(
'HOSTNAME'
):
k
,
v
=
line
.
split
(
'='
)
return
v
.
strip
()
finally
:
f
.
close
()
except
Exception
,
err
:
self
.
module
.
fail_json
(
msg
=
"failed to read hostname:
%
s"
%
str
(
err
))
...
...
@@ -192,14 +201,20 @@ class RedHatStrategy(GenericStrategy):
def
set_permanent_hostname
(
self
,
name
):
try
:
lines
=
[]
with
open
(
self
.
NETWORK_FILE
,
'rb'
)
as
f
:
f
=
open
(
self
.
NETWORK_FILE
,
'rb'
)
try
:
for
line
in
f
.
readlines
():
if
line
.
startswith
(
'HOSTNAME'
):
lines
.
append
(
"HOSTNAME=
%
s
\n
"
%
name
)
else
:
lines
.
append
(
line
)
with
open
(
self
.
NETWORK_FILE
,
'w+'
)
as
f
:
finally
:
f
.
close
()
f
=
open
(
self
.
NETWORK_FILE
,
'w+'
)
try
:
f
.
writelines
(
lines
)
finally
:
f
.
close
()
except
Exception
,
err
:
self
.
module
.
fail_json
(
msg
=
"failed to update hostname:
%
s"
%
str
(
err
))
...
...
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