2017-01-18 04:21:04 +00:00
|
|
|
- set_fact:
|
|
|
|
varname: WINPATH_TEST
|
|
|
|
|
|
|
|
- name: Remove {{ varname }} vars from user and machine scope
|
|
|
|
raw: '[Environment]::SetEnvironmentVariable("{{ varname }}", $null, "User"); [Environment]::SetEnvironmentVariable("{{ varname }}", $null, "Machine")'
|
|
|
|
|
|
|
|
- name: Set a var at the machine and user levels
|
|
|
|
win_path:
|
|
|
|
name: "{{ varname }}"
|
|
|
|
elements: C:\{{ item }}Path
|
|
|
|
scope: "{{ item }}"
|
|
|
|
with_items:
|
|
|
|
- machine
|
|
|
|
- user
|
|
|
|
register: pathout
|
|
|
|
|
|
|
|
- name: Get path value from machine and user levels
|
|
|
|
raw: '[Environment]::GetEnvironmentVariable("{{ varname }}","{{ item.item }}")'
|
|
|
|
with_items: "{{ pathout.results }}"
|
|
|
|
register: varout
|
|
|
|
|
|
|
|
- name: Ensure output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- item.0 is changed
|
2017-04-21 20:07:38 +00:00
|
|
|
- item.0.path_value == "C:\\" + item.0.item + "Path"
|
|
|
|
- item.1.stdout_lines[0] == 'C:\\' + item.0.item + 'Path'
|
2017-01-18 04:21:04 +00:00
|
|
|
with_together:
|
|
|
|
- "{{ pathout.results }}"
|
|
|
|
- "{{ varout.results }}"
|
|
|
|
|
|
|
|
- name: Remove {{ varname }} vars from user and machine scope
|
|
|
|
raw: '[Environment]::SetEnvironmentVariable("{{ varname }}", $null, "User"); [Environment]::SetEnvironmentVariable("{{ varname }}", $null, "Machine")'
|
|
|
|
|
|
|
|
- name: Create multi-element path
|
|
|
|
win_path:
|
|
|
|
name: "{{ varname }}"
|
|
|
|
elements:
|
|
|
|
- C:\PathZ
|
|
|
|
- C:\PathA
|
|
|
|
register: multiout
|
|
|
|
|
|
|
|
- name: Get path value
|
|
|
|
raw: $env:{{ varname }}
|
|
|
|
register: varout
|
|
|
|
|
|
|
|
- name: Ensure output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- multiout is changed
|
2017-01-18 04:21:04 +00:00
|
|
|
- multiout.path_value == "C:\\PathZ;C:\\PathA"
|
|
|
|
- varout.stdout_lines[0] == "C:\\PathZ;C:\\PathA"
|
|
|
|
|
|
|
|
- name: Add value to middle and end
|
|
|
|
win_path:
|
|
|
|
name: "{{ varname }}"
|
|
|
|
elements:
|
|
|
|
- C:\NewPath
|
|
|
|
- C:\PathA
|
|
|
|
- 'C:\PathWithTrailingBackslash\' # store with a trailing backslash
|
|
|
|
- '"C:\Quoted;With;Semicolons"' # embedded semicolon, wrapped in quotes
|
|
|
|
- '%SystemRoot%\stuff'
|
|
|
|
register: addout
|
|
|
|
|
|
|
|
- name: Get path value
|
|
|
|
raw: $env:{{ varname }}
|
|
|
|
register: varout
|
|
|
|
|
|
|
|
- name: Test idempotence- retry values to middle and end, test case-insensitive comparison, backslash canonicalization
|
|
|
|
win_path:
|
|
|
|
name: "{{ varname }}"
|
|
|
|
elements:
|
|
|
|
- c:\nEwPaTh
|
|
|
|
- c:\patha
|
|
|
|
- C:\pathwithtrailingbackslash # no trailing backslash, should be the same
|
|
|
|
- '"C:\Quoted;With;Semicolons"'
|
|
|
|
- '%SystemRoot%\stuff'
|
|
|
|
register: idemout
|
|
|
|
|
|
|
|
- name: Get path value
|
|
|
|
raw: $env:{{ varname }}
|
|
|
|
register: idemvarout
|
|
|
|
|
|
|
|
- name: Ensure output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- addout is changed
|
2017-01-18 04:21:04 +00:00
|
|
|
- addout.path_value == 'C:\\PathZ;C:\\NewPath;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";%SystemRoot%\stuff'
|
|
|
|
- varout.stdout_lines[0] == ('C:\\PathZ;C:\\NewPath;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";C:\Windows\stuff')
|
2017-11-27 22:58:08 +00:00
|
|
|
- idemout is not changed
|
2017-01-18 04:21:04 +00:00
|
|
|
- idemout.path_value == 'C:\\PathZ;C:\\NewPath;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";%SystemRoot%\stuff'
|
|
|
|
- idemvarout.stdout_lines[0] == ('C:\\PathZ;C:\\NewPath;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";C:\Windows\stuff')
|
|
|
|
|
|
|
|
- name: Remove single element
|
|
|
|
win_path:
|
|
|
|
name: "{{ varname }}"
|
|
|
|
elements: C:\NewPath
|
|
|
|
state: absent
|
|
|
|
register: removeout
|
|
|
|
|
|
|
|
- name: Get path value
|
|
|
|
raw: $env:{{ varname }}
|
|
|
|
register: varout
|
|
|
|
|
|
|
|
- name: Test idempotence- retry remove single element
|
|
|
|
win_path:
|
|
|
|
name: "{{ varname }}"
|
|
|
|
elements: C:\NewPath
|
|
|
|
state: absent
|
|
|
|
register: idemremoveout
|
|
|
|
|
|
|
|
- name: Get path value
|
|
|
|
raw: $env:{{ varname }}
|
|
|
|
register: idemvarout
|
|
|
|
|
|
|
|
- name: Ensure output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- removeout is changed
|
2017-01-18 04:21:04 +00:00
|
|
|
- removeout.path_value == 'C:\\PathZ;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";%SystemRoot%\stuff'
|
|
|
|
- varout.stdout_lines[0] == 'C:\\PathZ;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";C:\Windows\stuff'
|
2017-11-27 22:58:08 +00:00
|
|
|
- idemremoveout is not changed
|
2017-01-18 04:21:04 +00:00
|
|
|
- idemremoveout.path_value == 'C:\\PathZ;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";%SystemRoot%\stuff'
|
|
|
|
- idemvarout.stdout_lines[0] == 'C:\\PathZ;C:\\PathA;C:\\PathWithTrailingBackslash\\;"C:\Quoted;With;Semicolons";C:\Windows\stuff'
|
|
|
|
|
|
|
|
- name: Remove multiple elements
|
|
|
|
win_path:
|
|
|
|
name: "{{ varname }}"
|
|
|
|
elements:
|
|
|
|
- C:\PathWithTrailingBackslash # no trailing backslash
|
|
|
|
- c:\pathz
|
|
|
|
- '"C:\Quoted;With;Semicolons"'
|
|
|
|
- '%SystemRoot%\stuff\' # add trailing backslash
|
|
|
|
state: absent
|
|
|
|
register: removeout
|
|
|
|
|
|
|
|
- name: Get path value
|
|
|
|
raw: $env:{{ varname }}
|
|
|
|
register: varout
|
|
|
|
|
|
|
|
- name: Ensure output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- removeout is changed
|
2017-01-18 04:21:04 +00:00
|
|
|
- removeout.path_value == "C:\\PathA"
|
|
|
|
- varout.stdout_lines[0] == "C:\\PathA"
|
|
|
|
|
|
|
|
- name: Test check mode add
|
|
|
|
check_mode: yes
|
|
|
|
win_path:
|
|
|
|
name: "{{ varname }}"
|
|
|
|
elements:
|
|
|
|
- C:\MissingPath
|
|
|
|
register: checkadd
|
|
|
|
|
|
|
|
- name: Get path value
|
|
|
|
raw: $env:{{ varname }}
|
|
|
|
register: checkaddvarout
|
|
|
|
|
|
|
|
- name: Test check mode remove
|
|
|
|
check_mode: yes
|
|
|
|
win_path:
|
|
|
|
name: "{{ varname }}"
|
|
|
|
elements: C:\PathA
|
|
|
|
state: absent
|
|
|
|
register: checkremove
|
|
|
|
|
|
|
|
- name: Get path value
|
|
|
|
raw: $env:{{ varname }}
|
|
|
|
register: checkremovevarout
|
|
|
|
|
|
|
|
- name: Ensure output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 22:58:08 +00:00
|
|
|
- checkadd is changed
|
2017-01-18 04:21:04 +00:00
|
|
|
- checkadd.path_value == "C:\\PathA;C:\\MissingPath"
|
|
|
|
- checkaddvarout.stdout_lines[0] == "C:\\PathA" # shouldn't have actually changed the value
|
2017-11-27 22:58:08 +00:00
|
|
|
- checkremove is changed
|
2017-01-18 04:21:04 +00:00
|
|
|
- checkremove.path_value == ""
|
|
|
|
- checkremovevarout.stdout_lines[0] == "C:\\PathA" # shouldn't have actually changed the value
|
|
|
|
|
|
|
|
- name: Remove {{ varname }} vars from user and machine scope
|
|
|
|
raw: '[Environment]::SetEnvironmentVariable("{{ varname }}", $null, "User"); [Environment]::SetEnvironmentVariable("{{ varname }}", $null, "Machine")'
|