ansible.builtin.win_path (v2.9.27) — module

Manage Windows path environment variables

| "added in version" 2.3 of ansible.builtin"

Authors: Matt Davis (@nitzmahone)

preview | supported by core

Install Ansible via pip

Install with pip install ansible==2.9.27

Description

Allows element-based ordering, addition, and removal of Windows path environment variables.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Ensure that system32 and Powershell are present on the global system path, and in the specified order
  win_path:
    elements:
    - '%SystemRoot%\system32'
    - '%SystemRoot%\system32\WindowsPowerShell\v1.0'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Ensure that C:\Program Files\MyJavaThing is not on the current user's CLASSPATH
  win_path:
    name: CLASSPATH
    elements: C:\Program Files\MyJavaThing
    scope: user
    state: absent

Inputs

    
name:
    default: PATH
    description:
    - Target path environment variable name.
    type: str

scope:
    choices:
    - machine
    - user
    default: machine
    description:
    - The level at which the environment variable specified by C(name) should be managed
      (either for the current user or global machine scope).
    type: str

state:
    choices:
    - absent
    - present
    description:
    - Whether the path elements specified in C(elements) should be present or absent.
    type: str

elements:
    description:
    - A single path element, or a list of path elements (ie, directories) to add or remove.
    - When multiple elements are included in the list (and C(state) is C(present)), the
      elements are guaranteed to appear in the same relative order in the resultant path
      value.
    - Variable expansions (eg, C(%VARNAME%)) are allowed, and are stored unexpanded in
      the target path element.
    - Any existing path elements not mentioned in C(elements) are always preserved in
      their current order.
    - New path elements are appended to the path, and existing path elements may be moved
      closer to the end to satisfy the requested ordering.
    - Paths are compared in a case-insensitive fashion, and trailing backslashes are ignored
      for comparison purposes. However, note that trailing backslashes in YAML require
      quotes.
    required: true
    type: list

See also