community.windows.win_defrag (2.2.0) — module

Consolidate fragmented files on local volumes

Authors: Dag Wieers (@dagwieers)

Install collection

Install with ansible-galaxy collection install community.windows:==2.2.0


Add to requirements.yml

  collections:
    - name: community.windows
      version: 2.2.0

Description

Locates and consolidates fragmented files on local volumes to improve system performance.

More information regarding C(win_defrag) is available from: U(https://technet.microsoft.com/en-us/library/cc731650%28v%3Dws.11.aspx%29)


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Defragment all local volumes (in parallel)
  community.windows.win_defrag:
    parallel: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: 'Defragment all local volumes, except C: and D:'
  community.windows.win_defrag:
    exclude_volumes: [ C, D ]
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: 'Defragment volume D: with normal priority'
  community.windows.win_defrag:
    include_volumes: D
    priority: normal
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Consolidate free space (useful when reducing volumes)
  community.windows.win_defrag:
    freespace_consolidation: yes

Inputs

    
parallel:
    default: false
    description:
    - Run the operation on each volume in parallel in the background.
    type: bool

priority:
    choices:
    - low
    - normal
    default: low
    description:
    - Run the operation at low or normal priority.
    type: str

exclude_volumes:
    description:
    - A list of drive letters or mount point paths to exclude from defragmentation.
    elements: str
    type: list

include_volumes:
    description:
    - A list of drive letters or mount point paths of the volumes to be defragmented.
    - If this parameter is omitted, all volumes (not excluded) will be fragmented.
    elements: str
    type: list

freespace_consolidation:
    default: false
    description:
    - Perform free space consolidation on the specified volumes.
    type: bool

Outputs

changed:
  description: Whether or not any changes were made.
  returned: always
  sample: true
  type: bool
cmd:
  description: The complete command line used by the module.
  returned: always
  sample: defrag.exe /C /V
  type: str
msg:
  description: Possible error message on failure.
  returned: failed
  sample: Command 'defrag.exe' not found in $env:PATH.
  type: str
rc:
  description: The return code for the command.
  returned: always
  sample: 0
  type: int
stderr:
  description: The error output from the command.
  returned: always
  sample: null
  type: str
stdout:
  description: The standard output from the command.
  returned: always
  sample: Success.
  type: str