ansible.builtin.win_environment (v2.4.2.0-1) — module

Modifies environment variables on windows hosts.

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

Authors: Jon Hawkesworth (@jhawkesworth)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.4.2.0.post1

Description

Uses .net Environment to set or remove environment variables and can set at User, Machine or Process level.

User level environment variables will be set, but not available until the user has logged off and on again.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set an environment variable for all users
  win_environment:
    state: present
    name: TestVariable
    value: Test value
    level: machine
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove an environment variable for the current user
  win_environment:
    state: absent
    name: TestVariable
    level: user

Inputs

    
name:
    default: no default
    description:
    - The name of the environment variable
    required: true

level:
    choices:
    - machine
    - process
    - user
    default: no default
    description:
    - The level at which to set the environment variable.
    - Use 'machine' to set for all users.
    - Use 'user' to set for the current user that ansible is connected as.
    - Use 'process' to set for the current process.  Probably not that useful.
    required: true

state:
    choices:
    - present
    - absent
    default: present
    description:
    - present to ensure environment variable is set, or absent to ensure it is removed
    required: false

value:
    default: no default
    description:
    - The value to store in the environment variable. Can be omitted for state=absent
    required: false

Outputs

before_value:
  description:
  - the value of the environment key before a change, this is null if it didn't exist
  returned: always
  sample: C:\Windows\System32
  type: string
level:
  description: the level set when calling the module
  returned: always
  sample: machine
  type: string
name:
  description: the name of the environment key the module checked
  returned: always
  sample: JAVA_HOME
  type: string
value:
  description: the value the environment key has been set to
  returned: always
  sample: C:\Program Files\jdk1.8
  type: string