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
3f5440f7
Commit
3f5440f7
authored
Mar 18, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make modules set a valid working directory
Fixes #6546
parent
750d9e2d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
lib/ansible/module_utils/basic.py
+23
-0
No files found.
lib/ansible/module_utils/basic.py
View file @
3f5440f7
...
...
@@ -217,6 +217,9 @@ class AnsibleModule(object):
if
not
self
.
no_log
:
self
.
_log_invocation
()
# finally, make sure we're in a sane working dir
self
.
_set_cwd
()
def
load_file_common_arguments
(
self
,
params
):
'''
many modules deal with files, this encapsulates common
...
...
@@ -815,6 +818,26 @@ class AnsibleModule(object):
syslog
.
openlog
(
str
(
module
),
0
,
syslog
.
LOG_USER
)
syslog
.
syslog
(
syslog
.
LOG_NOTICE
,
unicode
(
msg
)
.
encode
(
'utf8'
))
def
_set_cwd
(
self
):
try
:
cwd
=
os
.
getcwd
()
if
not
os
.
access
(
cwd
,
os
.
F_OK
|
os
.
R_OK
):
raise
return
cwd
except
:
# we don't have access to the cwd, probably because of sudo.
# Try and move to a neutral location to prevent errors
for
cwd
in
[
os
.
path
.
expandvars
(
'$HOME'
),
tempfile
.
gettempdir
()]:
try
:
if
os
.
access
(
cwd
,
os
.
F_OK
|
os
.
R_OK
):
os
.
chdir
(
cwd
)
return
cwd
except
:
pass
# we won't error here, as it may *not* be a problem,
# and we don't want to break modules unnecessarily
return
None
def
get_bin_path
(
self
,
arg
,
required
=
False
,
opt_dirs
=
[]):
'''
find system executable in PATH.
...
...
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