community.internal_test_tools.files_collect (0.11.0) — module

Collect state of files and directories on disk

| "added in version" 0.3.0 of community.internal_test_tools"

Authors: Felix Fontein (@felixfontein)

Install collection

Install with ansible-galaxy collection install community.internal_test_tools:==0.11.0


Add to requirements.yml

  collections:
    - name: community.internal_test_tools
      version: 0.11.0

Description

This module collects the state (timestamps, attributes, content) of files and directories on disk and returns them. Use together with M(community.internal_test_tools.files_diff) to verify later on whether something changed, and if yes, what exactly changed.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Recursively collect information on all files in output_dir
  community.internal_test_tools.files_collect:
    directories:
      - path: "{{ output_dir }}"
  register: state
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# ... some tasks in between ...

- name: Verify whether any file changed in output_dir
  community.internal_test_tools.files_diff:
    state: "{{ state }}"

Inputs

    
files:
    description:
    - List of filenames to check.
    elements: dict
    suboptions:
      allow_not_existing:
        default: false
        description:
        - Whether to accept if the file does not exist (and mark it as a non-existing
          file in the output).
        type: bool
      check_content:
        default: false
        description:
        - Whether to store the content of the file, or only a checksum.
        - Storing the content allows to show a diff.
        type: bool
      path:
        description: Path to the directory.
        required: true
        type: path
    type: list

directories:
    description:
    - List of directories to check.
    elements: dict
    suboptions:
      check_content:
        default: false
        description:
        - Whether to store the content of the files, or only a checksum.
        - Storing the content allows to show a diff.
        type: bool
      path:
        description: Path to the directory.
        required: true
        type: path
      recursive:
        default: true
        description: Whether to consider subdirectories as well.
        type: bool
    type: list

Outputs

state:
  description:
  - The state of all files and directories.
  - Use the M(community.internal_test_tools.files_diff) module to validate against
    the original files.
  - The structure of every field in this dictionary not explicitly documented here
    might change at any point, or might vanish altogether without further notice.
    Do not rely on undocumented data!
  returned: success
  type: dict