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
7a8009f9
Commit
7a8009f9
authored
Oct 25, 2012
by
Daniel Hokka Zakrisson
Committed by
Michael DeHaan
Oct 25, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When atomically replacing files, copy attributes
parent
523f2bf3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
8 deletions
+16
-8
lib/ansible/module_common.py
+14
-0
library/authorized_key
+1
-7
library/copy
+1
-1
No files found.
lib/ansible/module_common.py
View file @
7a8009f9
...
@@ -594,6 +594,20 @@ class AnsibleModule(object):
...
@@ -594,6 +594,20 @@ class AnsibleModule(object):
self.fail_json(msg='Could not make backup of
%
s to
%
s:
%
s'
%
(fn, backupdest, e))
self.fail_json(msg='Could not make backup of
%
s to
%
s:
%
s'
%
(fn, backupdest, e))
return backupdest
return backupdest
def atomic_replace(self, src, dest):
'''atomically replace dest with src, copying attributes from dest'''
st = os.stat(dest)
os.chmod(src, st.st_mode & 07777)
try:
os.chown(src, st.st_uid, st.st_gid)
except OSError, e:
if e.errno != errno.EPERM:
raise
if self.selinux_enabled():
context = self.selinux_context(dest)
self.set_context_if_different(src, context, False)
os.rename(src, dest)
# == END DYNAMICALLY INSERTED CODE ===
# == END DYNAMICALLY INSERTED CODE ===
...
...
library/authorized_key
View file @
7a8009f9
...
@@ -125,13 +125,7 @@ def writekeys(module, filename, keys):
...
@@ -125,13 +125,7 @@ def writekeys(module, filename, keys):
except
IOError
,
e
:
except
IOError
,
e
:
module
.
fail_json
(
msg
=
"Failed to write to file
%
s:
%
s"
%
(
tmp_path
,
str
(
e
)))
module
.
fail_json
(
msg
=
"Failed to write to file
%
s:
%
s"
%
(
tmp_path
,
str
(
e
)))
f
.
close
()
f
.
close
()
try
:
module
.
atomic_replace
(
tmp_path
,
filename
)
shutil
.
copyfile
(
tmp_path
,
filename
)
os
.
unlink
(
tmp_path
)
except
IOError
,
e
:
module
.
fail_json
(
msg
=
"Failed to copy temp file to
%
s:
%
s"
%
(
filename
,
str
(
e
)))
except
OSError
,
e
:
module
.
fail_json
(
msg
=
"Failed to remove temp file:
%
s"
%
str
(
e
))
def
enforce_state
(
module
,
params
):
def
enforce_state
(
module
,
params
):
"""
"""
...
...
library/copy
View file @
7a8009f9
...
@@ -114,7 +114,7 @@ def main():
...
@@ -114,7 +114,7 @@ def main():
# might be an issue with exceeding path length
# might be an issue with exceeding path length
dest_tmp
=
"
%
s.
%
s.
%
s.tmp"
%
(
dest
,
os
.
getpid
(),
time
.
time
())
dest_tmp
=
"
%
s.
%
s.
%
s.tmp"
%
(
dest
,
os
.
getpid
(),
time
.
time
())
shutil
.
copyfile
(
src
,
dest_tmp
)
shutil
.
copyfile
(
src
,
dest_tmp
)
shutil
.
mov
e
(
dest_tmp
,
dest
)
module
.
atomic_replac
e
(
dest_tmp
,
dest
)
except
shutil
.
Error
:
except
shutil
.
Error
:
module
.
fail_json
(
msg
=
"failed to copy:
%
s and
%
s are the same"
%
(
src
,
dest
))
module
.
fail_json
(
msg
=
"failed to copy:
%
s and
%
s are the same"
%
(
src
,
dest
))
except
IOError
:
except
IOError
:
...
...
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