Note
This plugin is part of the ansible.windows collection (version 1.3.0).
To install it use: ansible-galaxy collection install ansible.windows
.
To use it in a playbook, specify: ansible.windows.win_environment
.
Parameter | Choices/Defaults | Comments |
---|---|---|
level string / required |
| 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. |
name string | The name of the environment variable. Required when state=absent. | |
state string |
| Set to present to ensure environment variable is set.Set to absent to ensure it is removed.When using variables, do not set this option. |
value string | The value to store in the environment variable. Must be set when state=present and cannot be an empty string. Should be omitted for state=absent and variables. | |
variables dictionary added in 1.3.0 of ansible.windows | A dictionary where multiple environment variables can be defined at once. Not valid when state is set. Variables with a value will be set ( present ) and variables with an empty value will be unset (absent ).
level applies to all vars defined this way. |
Note
before_value
and value
will be set to the last values when using variables. It’s best to use values
in that case if you need to find a specific variable’s before and after values.See also
The official documentation on the ansible.windows.win_path module.
- name: Set an environment variable for all users ansible.windows.win_environment: state: present name: TestVariable value: Test value level: machine - name: Remove an environment variable for the current user ansible.windows.win_environment: state: absent name: TestVariable level: user - name: Set several variables at once ansible.windows.win_environment: level: machine variables: TestVariable: Test value CUSTOM_APP_VAR: 'Very important value' ANOTHER_VAR: '{{ my_ansible_var }}' - name: Set and remove multiple variables at once ansible.windows.win_environment: level: user variables: TestVariable: Test value CUSTOM_APP_VAR: 'Very important value' ANOTHER_VAR: '{{ my_ansible_var }}' UNWANTED_VAR: '' # < this will be removed
Common return values are documented here, the following are the fields unique to this module:
Key | Returned | Description |
---|---|---|
before_value string | always | the value of the environment key before a change, this is null if it didn't exist Sample: C:\Windows\System32 |
value string | always | the value the environment key has been set to, this is null if removed Sample: C:\Program Files\jdk1.8 |
values dictionary added in 1.3.0 of ansible.windows | always | dictionary of before and after values; each key is a variable name, each value is another dict with before , after , and changed keys |
© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.11/collections/ansible/windows/win_environment_module.html