mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 23:51:09 +03:00
Allo the file fact scanner to take a list of paths instead of just one path
This commit is contained in:
parent
b1a8d2ce3c
commit
d76ee309c6
@ -6,7 +6,7 @@
|
|||||||
- scan_packages:
|
- scan_packages:
|
||||||
- scan_services:
|
- scan_services:
|
||||||
- scan_files:
|
- scan_files:
|
||||||
path: '{{ scan_file_path }}'
|
paths: '{{ scan_file_paths }}'
|
||||||
get_checksum: '{{ scan_use_checksum }}'
|
get_checksum: '{{ scan_use_checksum }}'
|
||||||
recursive: '{{ scan_use_recursive }}'
|
recursive: '{{ scan_use_recursive }}'
|
||||||
when: scan_file_path is defined
|
when: scan_file_paths is defined
|
@ -101,62 +101,63 @@ EXAMPLES = '''
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(path=dict(required=True),
|
argument_spec = dict(paths=dict(required=True, type='list'),
|
||||||
recursive=dict(required=False, default='no', type='bool'),
|
recursive=dict(required=False, default='no', type='bool'),
|
||||||
get_checksum=dict(required=False, default='no', type='bool')))
|
get_checksum=dict(required=False, default='no', type='bool')))
|
||||||
files = []
|
files = []
|
||||||
path = module.params.get('path')
|
paths = module.params.get('paths')
|
||||||
path = os.path.expanduser(path)
|
for path in paths:
|
||||||
if not os.path.exists(path) or not os.path.isdir(path):
|
path = os.path.expanduser(path)
|
||||||
module.fail_json(msg = "Given path must exist and be a directory")
|
if not os.path.exists(path) or not os.path.isdir(path):
|
||||||
|
module.fail_json(msg = "Given path must exist and be a directory")
|
||||||
|
|
||||||
get_checksum = module.params.get('get_checksum')
|
get_checksum = module.params.get('get_checksum')
|
||||||
should_recurse = module.params.get('recursive')
|
should_recurse = module.params.get('recursive')
|
||||||
if not should_recurse:
|
if not should_recurse:
|
||||||
path_list = [os.path.join(path, subpath) for subpath in os.listdir(path)]
|
path_list = [os.path.join(path, subpath) for subpath in os.listdir(path)]
|
||||||
else:
|
else:
|
||||||
path_list = [os.path.join(w_path, f) for w_path, w_names, w_file in os.walk(path) for f in w_file]
|
path_list = [os.path.join(w_path, f) for w_path, w_names, w_file in os.walk(path) for f in w_file]
|
||||||
for filepath in path_list:
|
for filepath in path_list:
|
||||||
try:
|
try:
|
||||||
st = os.stat(filepath)
|
st = os.stat(filepath)
|
||||||
except OSError:
|
except OSError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
mode = st.st_mode
|
mode = st.st_mode
|
||||||
d = {
|
d = {
|
||||||
'path' : filepath,
|
'path' : filepath,
|
||||||
'mode' : "%04o" % stat.S_IMODE(mode),
|
'mode' : "%04o" % stat.S_IMODE(mode),
|
||||||
'isdir' : stat.S_ISDIR(mode),
|
'isdir' : stat.S_ISDIR(mode),
|
||||||
'ischr' : stat.S_ISCHR(mode),
|
'ischr' : stat.S_ISCHR(mode),
|
||||||
'isblk' : stat.S_ISBLK(mode),
|
'isblk' : stat.S_ISBLK(mode),
|
||||||
'isreg' : stat.S_ISREG(mode),
|
'isreg' : stat.S_ISREG(mode),
|
||||||
'isfifo' : stat.S_ISFIFO(mode),
|
'isfifo' : stat.S_ISFIFO(mode),
|
||||||
'islnk' : stat.S_ISLNK(mode),
|
'islnk' : stat.S_ISLNK(mode),
|
||||||
'issock' : stat.S_ISSOCK(mode),
|
'issock' : stat.S_ISSOCK(mode),
|
||||||
'uid' : st.st_uid,
|
'uid' : st.st_uid,
|
||||||
'gid' : st.st_gid,
|
'gid' : st.st_gid,
|
||||||
'size' : st.st_size,
|
'size' : st.st_size,
|
||||||
'inode' : st.st_ino,
|
'inode' : st.st_ino,
|
||||||
'dev' : st.st_dev,
|
'dev' : st.st_dev,
|
||||||
'nlink' : st.st_nlink,
|
'nlink' : st.st_nlink,
|
||||||
'atime' : st.st_atime,
|
'atime' : st.st_atime,
|
||||||
'mtime' : st.st_mtime,
|
'mtime' : st.st_mtime,
|
||||||
'ctime' : st.st_ctime,
|
'ctime' : st.st_ctime,
|
||||||
'wusr' : bool(mode & stat.S_IWUSR),
|
'wusr' : bool(mode & stat.S_IWUSR),
|
||||||
'rusr' : bool(mode & stat.S_IRUSR),
|
'rusr' : bool(mode & stat.S_IRUSR),
|
||||||
'xusr' : bool(mode & stat.S_IXUSR),
|
'xusr' : bool(mode & stat.S_IXUSR),
|
||||||
'wgrp' : bool(mode & stat.S_IWGRP),
|
'wgrp' : bool(mode & stat.S_IWGRP),
|
||||||
'rgrp' : bool(mode & stat.S_IRGRP),
|
'rgrp' : bool(mode & stat.S_IRGRP),
|
||||||
'xgrp' : bool(mode & stat.S_IXGRP),
|
'xgrp' : bool(mode & stat.S_IXGRP),
|
||||||
'woth' : bool(mode & stat.S_IWOTH),
|
'woth' : bool(mode & stat.S_IWOTH),
|
||||||
'roth' : bool(mode & stat.S_IROTH),
|
'roth' : bool(mode & stat.S_IROTH),
|
||||||
'xoth' : bool(mode & stat.S_IXOTH),
|
'xoth' : bool(mode & stat.S_IXOTH),
|
||||||
'isuid' : bool(mode & stat.S_ISUID),
|
'isuid' : bool(mode & stat.S_ISUID),
|
||||||
'isgid' : bool(mode & stat.S_ISGID),
|
'isgid' : bool(mode & stat.S_ISGID),
|
||||||
}
|
}
|
||||||
if get_checksum and stat.S_ISREG(mode) and os.access(filepath, os.R_OK):
|
if get_checksum and stat.S_ISREG(mode) and os.access(filepath, os.R_OK):
|
||||||
d['checksum'] = module.sha1(filepath)
|
d['checksum'] = module.sha1(filepath)
|
||||||
files.append(d)
|
files.append(d)
|
||||||
results = dict(ansible_facts=dict(files=files))
|
results = dict(ansible_facts=dict(files=files))
|
||||||
module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user