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
29ac1a8e
Commit
29ac1a8e
authored
Sep 24, 2012
by
Michael Lambert
Committed by
Michael DeHaan
Sep 24, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace os.access with stat calls for determining the executability of a given path.
parent
734db4ff
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
2 deletions
+16
-2
lib/ansible/inventory/__init__.py
+1
-1
lib/ansible/module_common.py
+8
-1
lib/ansible/utils.py
+7
-0
No files found.
lib/ansible/inventory/__init__.py
View file @
29ac1a8e
...
@@ -76,7 +76,7 @@ class Inventory(object):
...
@@ -76,7 +76,7 @@ class Inventory(object):
all
.
add_host
(
Host
(
tokens
[
0
],
tokens
[
1
]))
all
.
add_host
(
Host
(
tokens
[
0
],
tokens
[
1
]))
else
:
else
:
all
.
add_host
(
Host
(
x
))
all
.
add_host
(
Host
(
x
))
elif
os
.
access
(
host_list
,
os
.
X_OK
):
elif
utils
.
is_executable
(
host_list
):
self
.
_is_script
=
True
self
.
_is_script
=
True
self
.
parser
=
InventoryScript
(
filename
=
host_list
)
self
.
parser
=
InventoryScript
(
filename
=
host_list
)
self
.
groups
=
self
.
parser
.
groups
.
values
()
self
.
groups
=
self
.
parser
.
groups
.
values
()
...
...
lib/ansible/module_common.py
View file @
29ac1a8e
...
@@ -49,6 +49,7 @@ import syslog
...
@@ -49,6 +49,7 @@ import syslog
import types
import types
import time
import time
import shutil
import shutil
import stat
try:
try:
from hashlib import md5 as _md5
from hashlib import md5 as _md5
...
@@ -247,7 +248,7 @@ class AnsibleModule(object):
...
@@ -247,7 +248,7 @@ class AnsibleModule(object):
paths.append(p)
paths.append(p)
for d in paths:
for d in paths:
path = os.path.join(d, arg)
path = os.path.join(d, arg)
if os.path.exists(path) and
os.access(path, os.X_OK
):
if os.path.exists(path) and
self.is_executable(path
):
bin_path = path
bin_path = path
break
break
if required and bin_path is None:
if required and bin_path is None:
...
@@ -282,6 +283,12 @@ class AnsibleModule(object):
...
@@ -282,6 +283,12 @@ class AnsibleModule(object):
print self.jsonify(kwargs)
print self.jsonify(kwargs)
sys.exit(1)
sys.exit(1)
def is_executable(path):
'''is the given path executable?'''
return (stat.S_IXUSR & os.stat(path)[stat.ST_MODE]
or stat.S_IXGRP & os.stat(path)[stat.ST_MODE]
or stat.S_IXOTH & os.stat(path)[stat.ST_MODE])
def md5(self, filename):
def md5(self, filename):
''' Return MD5 hex digest of local file, or None if file is not present. '''
''' Return MD5 hex digest of local file, or None if file is not present. '''
if not os.path.exists(filename):
if not os.path.exists(filename):
...
...
lib/ansible/utils.py
View file @
29ac1a8e
...
@@ -32,6 +32,7 @@ import StringIO
...
@@ -32,6 +32,7 @@ import StringIO
import
imp
import
imp
import
glob
import
glob
import
subprocess
import
subprocess
import
stat
VERBOSITY
=
0
VERBOSITY
=
0
...
@@ -100,6 +101,12 @@ def check_conditional(conditional):
...
@@ -100,6 +101,12 @@ def check_conditional(conditional):
return
var
.
startswith
(
"$"
)
return
var
.
startswith
(
"$"
)
return
eval
(
conditional
)
return
eval
(
conditional
)
def
is_executable
(
path
):
'''is the given path executable?'''
return
(
stat
.
S_IXUSR
&
os
.
stat
(
path
)[
stat
.
ST_MODE
]
or
stat
.
S_IXGRP
&
os
.
stat
(
path
)[
stat
.
ST_MODE
]
or
stat
.
S_IXOTH
&
os
.
stat
(
path
)[
stat
.
ST_MODE
])
def
prepare_writeable_dir
(
tree
):
def
prepare_writeable_dir
(
tree
):
''' make sure a directory exists and is writeable '''
''' make sure a directory exists and is writeable '''
...
...
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