ShIRann Chen 2 weeks ago committed by GitHub
commit 9462d3a6a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
minor_changes:
- find - add a checksum_algorithm parameter to specify which type of checksum the module will return

@ -29,6 +29,9 @@ options:
- You can choose seconds, minutes, hours, days, or weeks by specifying the
first letter of any of those words (e.g., "1w").
type: str
get_checksum:
default: no
version_added: 2.18
patterns:
default: []
description:
@ -131,11 +134,6 @@ options:
- Set this to V(true) to follow symlinks in path for systems with python 2.6+.
type: bool
default: no
get_checksum:
description:
- Set this to V(true) to retrieve a file's SHA1 checksum.
type: bool
default: no
use_regex:
description:
- If V(false), the patterns are file globs (shell).
@ -154,7 +152,7 @@ options:
- When doing a C(contains) search, determine the encoding of the files to be searched.
type: str
version_added: "2.17"
extends_documentation_fragment: action_common_attributes
extends_documentation_fragment: [action_common_attributes, checksum_common]
attributes:
check_mode:
details: since this action does not modify the target it just executes normally during check mode
@ -463,6 +461,9 @@ def main():
hidden=dict(type='bool', default=False),
follow=dict(type='bool', default=False),
get_checksum=dict(type='bool', default=False),
checksum_algorithm=dict(type='str', default='sha1',
choices=['md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512'],
aliases=['checksum', 'checksum_algo']),
use_regex=dict(type='bool', default=False),
depth=dict(type='int'),
mode=dict(type='raw'),
@ -560,7 +561,7 @@ def main():
r.update(statinfo(st))
if stat.S_ISREG(st.st_mode) and params['get_checksum']:
r['checksum'] = module.sha1(fsname)
r['checksum'] = module.digest_from_file(fsname, params['checksum_algorithm'])
if stat.S_ISREG(st.st_mode):
if sizefilter(st, size):
@ -585,7 +586,7 @@ def main():
r.update(statinfo(st))
if params['get_checksum']:
r['checksum'] = module.sha1(fsname)
r['checksum'] = module.digest_from_file(fsname, params['checksum_algorithm'])
filelist.append(r)
elif stat.S_ISLNK(st.st_mode) and params['file_type'] == 'link':

@ -26,22 +26,8 @@ options:
type: bool
default: no
get_checksum:
description:
- Whether to return a checksum of the file.
type: bool
default: yes
version_added: "1.8"
checksum_algorithm:
description:
- Algorithm to determine checksum of file.
- Will throw an error if the host is unable to use specified algorithm.
- The remote host has to support the hashing method specified, V(md5)
can be unavailable if the host is FIPS-140 compliant.
type: str
choices: [ md5, sha1, sha224, sha256, sha384, sha512 ]
default: sha1
aliases: [ checksum, checksum_algo ]
version_added: "2.0"
get_mime:
description:
- Use file magic and return data about the nature of the file. this uses
@ -61,6 +47,7 @@ options:
version_added: "2.3"
extends_documentation_fragment:
- action_common_attributes
- checksum_common
attributes:
check_mode:
support: full

@ -0,0 +1,25 @@
# Copyright (c) 2024 ShIRann Chen <shirannx@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
class ModuleDocFragment(object):
DOCUMENTATION = r"""
options:
checksum_algorithm:
description:
- Algorithm to determine checksum of file.
- Will throw an error if the host is unable to use specified algorithm.
- The remote host has to support the hashing method specified, V(md5)
can be unavailable if the host is FIPS-140 compliant.
- Availability might be restricted by the target system, for example FIPS systems won't allow md5 use
type: str
choices: [ md5, sha1, sha224, sha256, sha384, sha512 ]
default: sha1
aliases: [ checksum, checksum_algo ]
get_checksum:
description:
- Whether to return a checksum of the file.
type: bool
"""

@ -227,6 +227,29 @@
that:
- success_to_read_right_encoding_file.matched == 1
- name: specify the checksum_algo
register: find_by_specific_algo_res
find:
paths: "{{ remote_tmp_dir_test }}"
get_checksum: true
checksum_algorithm: md5
- debug: var=find_by_specific_algo_res
- name: get the md5 checksum by stat
register: all_files_st
stat:
get_checksum: true
checksum_algorithm: md5
path: "{{ item.path }}"
loop: "{{ find_by_specific_algo_res.files }}"
- assert:
that: "all_files_st.results[index].stat.checksum == item.checksum"
loop: "{{ find_by_specific_algo_res.files }}"
loop_control:
index_var: index
- name: read a gbk file by non-exists encoding
find:
paths: "{{ remote_tmp_dir_test }}"

Loading…
Cancel
Save