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
53d71a39
Commit
53d71a39
authored
Feb 25, 2014
by
Brian Coca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added octal representation of mode and made md5 checksumming optional
Signed-off-by: Brian Coca <briancoca+dev@gmail.com>
parent
6ed48b5a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
4 deletions
+16
-4
library/files/stat
+16
-4
No files found.
library/files/stat
View file @
53d71a39
...
@@ -34,6 +34,12 @@ options:
...
@@ -34,6 +34,12 @@ options:
required: false
required: false
default: no
default: no
aliases: []
aliases: []
get_md5:
description:
- Whether to return the md5 sum o fthe file
required: false
default: yes
aliases: []
author: Bruce Pennypacker
author: Bruce Pennypacker
'''
'''
...
@@ -51,6 +57,9 @@ EXAMPLES = '''
...
@@ -51,6 +57,9 @@ EXAMPLES = '''
register: p
register: p
- debug: msg="Path exists and is a directory"
- debug: msg="Path exists and is a directory"
when: p.stat.isdir is defined and p.stat.isdir == true
when: p.stat.isdir is defined and p.stat.isdir == true
# Don't do md5 checksum
- stat: path=/path/to/myhugefile get_md5=no
'''
'''
import
os
import
os
...
@@ -62,7 +71,8 @@ def main():
...
@@ -62,7 +71,8 @@ def main():
module
=
AnsibleModule
(
module
=
AnsibleModule
(
argument_spec
=
dict
(
argument_spec
=
dict
(
path
=
dict
(
required
=
True
),
path
=
dict
(
required
=
True
),
follow
=
dict
(
default
=
'no'
,
type
=
'bool'
)
follow
=
dict
(
default
=
'no'
,
type
=
'bool'
),
get_md5
=
dict
(
default
=
'yes'
,
type
=
'bool'
)
),
),
supports_check_mode
=
True
supports_check_mode
=
True
)
)
...
@@ -70,6 +80,7 @@ def main():
...
@@ -70,6 +80,7 @@ def main():
path
=
module
.
params
.
get
(
'path'
)
path
=
module
.
params
.
get
(
'path'
)
path
=
os
.
path
.
expanduser
(
path
)
path
=
os
.
path
.
expanduser
(
path
)
follow
=
module
.
params
.
get
(
'follow'
)
follow
=
module
.
params
.
get
(
'follow'
)
get_md5
=
module
.
params
.
get
(
'get_md5'
)
try
:
try
:
if
follow
:
if
follow
:
...
@@ -80,7 +91,7 @@ def main():
...
@@ -80,7 +91,7 @@ def main():
if
e
.
errno
==
errno
.
ENOENT
:
if
e
.
errno
==
errno
.
ENOENT
:
d
=
{
'exists'
:
False
}
d
=
{
'exists'
:
False
}
module
.
exit_json
(
changed
=
False
,
stat
=
d
)
module
.
exit_json
(
changed
=
False
,
stat
=
d
)
module
.
fail_json
(
msg
=
e
.
strerror
)
module
.
fail_json
(
msg
=
e
.
strerror
)
mode
=
st
.
st_mode
mode
=
st
.
st_mode
...
@@ -89,6 +100,7 @@ def main():
...
@@ -89,6 +100,7 @@ def main():
d
=
{
d
=
{
'exists'
:
True
,
'exists'
:
True
,
'mode'
:
S_IMODE
(
mode
),
'mode'
:
S_IMODE
(
mode
),
'octal'
:
"
%04
o"
%
S_IMODE
(
mode
),
'isdir'
:
S_ISDIR
(
mode
),
'isdir'
:
S_ISDIR
(
mode
),
'ischr'
:
S_ISCHR
(
mode
),
'ischr'
:
S_ISCHR
(
mode
),
'isblk'
:
S_ISBLK
(
mode
),
'isblk'
:
S_ISBLK
(
mode
),
...
@@ -121,7 +133,7 @@ def main():
...
@@ -121,7 +133,7 @@ def main():
if
S_ISLNK
(
mode
):
if
S_ISLNK
(
mode
):
d
[
'lnk_source'
]
=
os
.
path
.
realpath
(
path
)
d
[
'lnk_source'
]
=
os
.
path
.
realpath
(
path
)
if
S_ISREG
(
mode
):
if
S_ISREG
(
mode
)
and
get_md5
:
d
[
'md5'
]
=
module
.
md5
(
path
)
d
[
'md5'
]
=
module
.
md5
(
path
)
try
:
try
:
...
@@ -130,7 +142,7 @@ def main():
...
@@ -130,7 +142,7 @@ def main():
d
[
'pw_name'
]
=
pw
.
pw_name
d
[
'pw_name'
]
=
pw
.
pw_name
except
:
except
:
pass
pass
module
.
exit_json
(
changed
=
False
,
stat
=
d
)
module
.
exit_json
(
changed
=
False
,
stat
=
d
)
...
...
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