diff --git a/changelogs/fragments/260-description-checkmode.yml b/changelogs/fragments/260-description-checkmode.yml new file mode 100644 index 00000000..ec746d12 --- /dev/null +++ b/changelogs/fragments/260-description-checkmode.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - win_group - fixed ``description`` setting for a group that doesn't exist when running in check_mode (https://github.com/ansible-collections/ansible.windows/pull/260). \ No newline at end of file diff --git a/plugins/modules/win_group.ps1 b/plugins/modules/win_group.ps1 index 35697f40..1b30dc4a 100644 --- a/plugins/modules/win_group.ps1 +++ b/plugins/modules/win_group.ps1 @@ -32,8 +32,8 @@ try { If ($null -ne $description) { IF (-not $group.description -or $group.description -ne $description) { - $group.description = $description If (-not $check_mode) { + $group.description = $description $group.SetInfo() } $result.changed = $true diff --git a/tests/integration/targets/win_group/tasks/main.yml b/tests/integration/targets/win_group/tasks/main.yml index f66e3c2e..5e328394 100644 --- a/tests/integration/targets/win_group/tasks/main.yml +++ b/tests/integration/targets/win_group/tasks/main.yml @@ -32,6 +32,20 @@ that: - "win_group_create_noname is failed" +- name: set a group description on a missing group in check mode + win_group: + name: "{{test_win_group_name}}" + description: "{{test_win_group_description}}" + check_mode: true + register: win_group_checkmode_description + ignore_errors: true + +- name: check that description setting in check_mode passes if group doesn't exist + assert: + that: + - "win_group_checkmode_description is changed" + - "win_group_checkmode_description is not failed" + - name: create test group with invalid state parameter win_group: name: "{{test_win_group_name}}"