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
88c907af
Commit
88c907af
authored
Jun 30, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3340 from bpennypacker/stat
get file/path facts via 'stat'
parents
71b9be50
c47d1214
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
0 deletions
+109
-0
library/files/stat
+109
-0
No files found.
library/files/stat
0 → 100644
View file @
88c907af
#!/usr/bin/python
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION
=
'''
---
module: stat
version_added: "1.3"
short_description: retrieve file or file system status
description:
- Retrieves facts for a file similar to the linux/unix 'stat' command.
options:
path:
description:
- The full path of the file/object to get the facts of
required: true
default: null
aliases: []
author: Bruce Pennypacker
'''
EXAMPLES
=
'''
# Obtain the stats of /etc/foo.conf
- stats: >
path=/etc/foo.conf
'''
import
os
import
sys
from
stat
import
*
from
pprint
import
pprint
def
main
():
module
=
AnsibleModule
(
argument_spec
=
dict
(
path
=
dict
(
required
=
True
),
)
)
path
=
module
.
params
.
get
(
'path'
)
try
:
st
=
os
.
stat
(
path
)
except
OSError
,
e
:
if
e
.
errno
==
errno
.
ENOENT
:
d
=
{
'exists'
:
False
}
module
.
exit_json
(
changed
=
False
,
stat
=
d
)
module
.
fail_json
(
msg
=
e
.
strerror
)
mode
=
st
.
st_mode
# back to ansible
d
=
{
'exists'
:
True
,
'mode'
:
S_IMODE
(
mode
),
'isdir'
:
S_ISDIR
(
mode
),
'ischr'
:
S_ISCHR
(
mode
),
'isblk'
:
S_ISBLK
(
mode
),
'isreg'
:
S_ISREG
(
mode
),
'isfifo'
:
S_ISFIFO
(
mode
),
'islnk'
:
S_ISLNK
(
mode
),
'issock'
:
S_ISSOCK
(
mode
),
'uid'
:
st
.
st_uid
,
'gid'
:
st
.
st_gid
,
'size'
:
st
.
st_size
,
'inode'
:
st
.
st_ino
,
'dev'
:
st
.
st_dev
,
'nlink'
:
st
.
st_nlink
,
'atime'
:
st
.
st_atime
,
'mtime'
:
st
.
st_mtime
,
'ctime'
:
st
.
st_ctime
,
'wusr'
:
bool
(
mode
&
stat
.
S_IWUSR
),
'rusr'
:
bool
(
mode
&
stat
.
S_IRUSR
),
'xusr'
:
bool
(
mode
&
stat
.
S_IXUSR
),
'wgrp'
:
bool
(
mode
&
stat
.
S_IWGRP
),
'rgrp'
:
bool
(
mode
&
stat
.
S_IRGRP
),
'xgrp'
:
bool
(
mode
&
stat
.
S_IXGRP
),
'woth'
:
bool
(
mode
&
stat
.
S_IWOTH
),
'roth'
:
bool
(
mode
&
stat
.
S_IROTH
),
'xoth'
:
bool
(
mode
&
stat
.
S_IXOTH
),
'isuid'
:
bool
(
mode
&
stat
.
S_ISUID
),
'isgid'
:
bool
(
mode
&
stat
.
S_ISGID
),
}
if
S_ISDIR
(
mode
)
and
os
.
path
.
islink
(
path
):
d
[
'isdir'
]
=
False
d
[
'islnk'
]
=
True
module
.
exit_json
(
changed
=
False
,
stat
=
d
)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main
()
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