From a6b7d0d00b1efbd81bd3da41448760b5f124ad28 Mon Sep 17 00:00:00 2001 From: Shachaf92 Date: Fri, 5 Jul 2019 01:44:07 +0300 Subject: [PATCH] win_domain_user and win_domain_group: add created result boolean (#57901) * win_domain_user and win_domain_group: add created result boolean * Fix YML * add docs * brackets * Update win_domain_group.py * Update win_domain_user.py * Update win_domain_user.ps1 * fix indent --- ...er-win_domain_group-add-created-result-boolean.yml | 2 ++ lib/ansible/modules/windows/win_domain_group.ps1 | 2 ++ lib/ansible/modules/windows/win_domain_group.py | 5 +++++ lib/ansible/modules/windows/win_domain_user.ps1 | 2 ++ lib/ansible/modules/windows/win_domain_user.py | 5 +++++ .../targets/win_domain_group/tasks/main.yml | 11 +++++++++++ 6 files changed, 27 insertions(+) create mode 100644 changelogs/fragments/win_domain_user-win_domain_group-add-created-result-boolean.yml diff --git a/changelogs/fragments/win_domain_user-win_domain_group-add-created-result-boolean.yml b/changelogs/fragments/win_domain_user-win_domain_group-add-created-result-boolean.yml new file mode 100644 index 00000000000..0ae590af96a --- /dev/null +++ b/changelogs/fragments/win_domain_user-win_domain_group-add-created-result-boolean.yml @@ -0,0 +1,2 @@ +minor_changes: +- "win_domain_user and win_domain_group: add created result boolean (https://github.com/ansible/ansible/issues/57547)" \ No newline at end of file diff --git a/lib/ansible/modules/windows/win_domain_group.ps1 b/lib/ansible/modules/windows/win_domain_group.ps1 index ecb965a5b13..bea8b5045d0 100644 --- a/lib/ansible/modules/windows/win_domain_group.ps1 +++ b/lib/ansible/modules/windows/win_domain_group.ps1 @@ -28,6 +28,7 @@ $domain_server = Get-AnsibleParam -obj $params -name "domain_server" -type "str" $result = @{ changed = $false + created = $false } if ($diff_mode) { @@ -289,6 +290,7 @@ if ($state -eq "absent") { Fail-Json $result "failed to create group $($name): $($_.Exception.Message)" } $result.changed = $true + $result.created = $true } # set the protection value diff --git a/lib/ansible/modules/windows/win_domain_group.py b/lib/ansible/modules/windows/win_domain_group.py index 6542dee0f86..641933233ca 100644 --- a/lib/ansible/modules/windows/win_domain_group.py +++ b/lib/ansible/modules/windows/win_domain_group.py @@ -234,4 +234,9 @@ sid: returned: group exists type: str sample: S-1-5-21-2171456218-3732823212-122182344-1189 +created: + description: Whether a group was created + returned: always + type: bool + sample: true ''' diff --git a/lib/ansible/modules/windows/win_domain_user.ps1 b/lib/ansible/modules/windows/win_domain_user.ps1 index def9c1e08b0..4584f0c7384 100644 --- a/lib/ansible/modules/windows/win_domain_user.ps1 +++ b/lib/ansible/modules/windows/win_domain_user.ps1 @@ -13,6 +13,7 @@ try { $result = @{ changed = $false + created = $false password_updated = $false } @@ -96,6 +97,7 @@ If ($state -eq 'present') { New-ADUser -Name $username -WhatIf:$check_mode @extra_args } $new_user = $true + $result.created = $true $result.changed = $true If ($check_mode) { Exit-Json $result diff --git a/lib/ansible/modules/windows/win_domain_user.py b/lib/ansible/modules/windows/win_domain_user.py index de88643b7c4..e4da32f7ce8 100644 --- a/lib/ansible/modules/windows/win_domain_user.py +++ b/lib/ansible/modules/windows/win_domain_user.py @@ -362,4 +362,9 @@ user_cannot_change_password: returned: always type: str sample: false +created: + description: Whether a user was created + returned: always + type: bool + sample: true ''' diff --git a/test/integration/targets/win_domain_group/tasks/main.yml b/test/integration/targets/win_domain_group/tasks/main.yml index 5e6499bf525..663a59a1b81 100644 --- a/test/integration/targets/win_domain_group/tasks/main.yml +++ b/test/integration/targets/win_domain_group/tasks/main.yml @@ -52,6 +52,7 @@ - name: assert create group with defaults assert: that: + - create_default is created - create_default is changed - create_default.category == 'Security' - create_default.description == None @@ -76,6 +77,7 @@ assert: that: - create_default_again is not changed + - create_default_again is not created - name: remove group check win_domain_group: @@ -109,6 +111,7 @@ assert: that: - remove_group is changed + - remove_group is not created - remove_group_actual.rc == 1 - name: remove group again @@ -121,6 +124,7 @@ assert: that: - remove_group_again is not changed + - remove_group_again is not created - name: create non default group check win_domain_group: @@ -148,6 +152,7 @@ assert: that: - create_non_default_check is changed + - create_non_default_check is created - create_non_default_actual_check.rc == 1 - name: create non default group @@ -175,6 +180,7 @@ assert: that: - create_non_default is changed + - create_non_default is created - create_non_default.category == 'Distribution' - create_non_default.description == 'Group Description' - create_non_default.display_name == 'Group Display Name' @@ -208,6 +214,7 @@ assert: that: - create_non_default_again is not changed + - create_non_default_again is not created - name: try and move group with protection mode on win_domain_group: @@ -241,6 +248,7 @@ assert: that: - modify_existing_check is changed + - modify_existing_check is not created - modify_existing_actual_check.stdout == 'CN=' + test_win_domain_group_name + ',' + test_win_domain_group_ou_path + '\r\n' - name: modify existing group @@ -267,6 +275,7 @@ assert: that: - modify_existing is changed + - modify_existing is not created - modify_existing.category == 'Security' - modify_existing.description == 'New Description' - modify_existing.display_name == 'New Display Name' @@ -300,6 +309,7 @@ assert: that: - modify_existing_again is not changed + - modify_existing_again is not created - name: fail change managed_by to invalid user win_domain_group: @@ -333,6 +343,7 @@ assert: that: - delete_with_force is changed + - delete_with_force is not created - delete_with_force_actual.rc == 1 - name: ensure the test group is deleted after the test