mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-09 06:40:03 -07:00
win_chocolatey_config: added module to manage Chocolatey config (#42915)
This commit is contained in:
parent
7ae5912d91
commit
8447f25e10
5 changed files with 356 additions and 0 deletions
1
test/integration/targets/win_chocolatey_config/aliases
Normal file
1
test/integration/targets/win_chocolatey_config/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
windows/ci/group1
|
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
- name: ensure Chocolatey is installed
|
||||
win_chocolatey:
|
||||
name: chocolatey
|
||||
state: present
|
||||
|
||||
- name: create a copy of the existing config file
|
||||
win_copy:
|
||||
src: C:\ProgramData\chocolatey\config\chocolatey.config
|
||||
dest: C:\ProgramData\chocolatey\config\chocolatey.config.ansiblebak
|
||||
remote_src: yes
|
||||
|
||||
- name: unset config setting as baseline
|
||||
win_chocolatey_config:
|
||||
name: cacheLocation
|
||||
state: absent
|
||||
|
||||
- block:
|
||||
- name: run tests
|
||||
include_tasks: tests.yml
|
||||
|
||||
always:
|
||||
- name: restore config file
|
||||
win_copy:
|
||||
src: C:\ProgramData\chocolatey\config\chocolatey.config.ansiblebak
|
||||
dest: C:\ProgramData\chocolatey\config\chocolatey.config
|
||||
remote_src: yes
|
||||
|
||||
- name: remove the backup config file
|
||||
win_file:
|
||||
path: C:\ProgramData\chocolatey\config\chocolatey.config.ansiblebak
|
||||
state: absent
|
141
test/integration/targets/win_chocolatey_config/tasks/tests.yml
Normal file
141
test/integration/targets/win_chocolatey_config/tasks/tests.yml
Normal file
|
@ -0,0 +1,141 @@
|
|||
---
|
||||
- name: fail if value is not set and state=present
|
||||
win_chocolatey_config:
|
||||
name: cacheLocation
|
||||
state: present
|
||||
register: fail_no_value
|
||||
failed_when: 'fail_no_value.msg != "Get-AnsibleParam: Missing required argument: value"'
|
||||
|
||||
- name: fail to set invalid config name
|
||||
win_chocolatey_config:
|
||||
name: fake
|
||||
state: present
|
||||
value: value
|
||||
register: fail_invalid_name
|
||||
failed_when: '"The Chocolatey config ''fake'' is not an existing config value, check the spelling. Valid config names: " not in fail_invalid_name.msg'
|
||||
|
||||
- name: set config setting (check mode)
|
||||
win_chocolatey_config:
|
||||
name: cacheLocation
|
||||
state: present
|
||||
value: C:\temp
|
||||
check_mode: yes
|
||||
register: set_check
|
||||
|
||||
- name: get actual config setting (check mode)
|
||||
win_command: choco.exe config get -r --name cacheLocation
|
||||
register: set_actual_check
|
||||
|
||||
- name: assert set config setting (check mode)
|
||||
assert:
|
||||
that:
|
||||
- set_check is changed
|
||||
- set_actual_check.stdout_lines == [""]
|
||||
|
||||
- name: set config setting
|
||||
win_chocolatey_config:
|
||||
name: cacheLocation
|
||||
state: present
|
||||
value: C:\temp
|
||||
register: set
|
||||
|
||||
- name: get actual config setting
|
||||
win_command: choco.exe config get -r --name cacheLocation
|
||||
register: set_actual
|
||||
|
||||
- name: assert set config setting
|
||||
assert:
|
||||
that:
|
||||
- set is changed
|
||||
- set_actual.stdout_lines == ["C:\\temp"]
|
||||
|
||||
- name: change config value (check mode)
|
||||
win_chocolatey_config:
|
||||
name: cacheLocation
|
||||
state: present
|
||||
value: C:\temp2
|
||||
check_mode: yes
|
||||
register: change_check
|
||||
|
||||
- name: get actual config setting (check mode)
|
||||
win_command: choco.exe config get -r --name cacheLocation
|
||||
register: change_actual_check
|
||||
|
||||
- name: assert change config value (check mode)
|
||||
assert:
|
||||
that:
|
||||
- change_check is changed
|
||||
- change_actual_check.stdout_lines == ["C:\\temp"]
|
||||
|
||||
- name: change config value
|
||||
win_chocolatey_config:
|
||||
name: cacheLocation
|
||||
state: present
|
||||
value: C:\temp2
|
||||
register: change
|
||||
|
||||
- name: get actual config setting
|
||||
win_command: choco.exe config get -r --name cacheLocation
|
||||
register: change_actual
|
||||
|
||||
- name: assert change config value
|
||||
assert:
|
||||
that:
|
||||
- change is changed
|
||||
- change_actual.stdout_lines == ["C:\\temp2"]
|
||||
|
||||
- name: change config value (idempotent)
|
||||
win_chocolatey_config:
|
||||
name: cacheLocation
|
||||
state: present
|
||||
value: C:\temp2
|
||||
register: change_again
|
||||
|
||||
- name: assert change config value (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not change_again is changed
|
||||
|
||||
- name: unset config value (check mode)
|
||||
win_chocolatey_config:
|
||||
name: cacheLocation
|
||||
state: absent
|
||||
check_mode: yes
|
||||
register: unset_check
|
||||
|
||||
- name: get actual config setting (check mode)
|
||||
win_command: choco.exe config get -r --name cacheLocation
|
||||
register: unset_actual_check
|
||||
|
||||
- name: assert unset config value (check mode)
|
||||
assert:
|
||||
that:
|
||||
- unset_check is changed
|
||||
- unset_actual_check.stdout_lines == ["C:\\temp2"]
|
||||
|
||||
- name: unset config value
|
||||
win_chocolatey_config:
|
||||
name: cacheLocation
|
||||
state: absent
|
||||
register: unset
|
||||
|
||||
- name: get actual config setting
|
||||
win_command: choco.exe config get -r --name cacheLocation
|
||||
register: unset_actual
|
||||
|
||||
- name: assert unset config value
|
||||
assert:
|
||||
that:
|
||||
- unset is changed
|
||||
- unset_actual.stdout_lines == [""]
|
||||
|
||||
- name: unset config value (idempotent)
|
||||
win_chocolatey_config:
|
||||
name: cacheLocation
|
||||
state: absent
|
||||
register: unset_again
|
||||
|
||||
- name: assert unset config value (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not unset_again is changed
|
Loading…
Add table
Add a link
Reference in a new issue