Skip to content

Commit

Permalink
win_domain_user and win_domain_group: add created result boolean (ans…
Browse files Browse the repository at this point in the history
…ible#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
  • Loading branch information
ShachafGoldstein authored and jborean93 committed Jul 4, 2019
1 parent 07edcab commit a6b7d0d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "win_domain_user and win_domain_group: add created result boolean (https://github.com/ansible/ansible/issues/57547)"
2 changes: 2 additions & 0 deletions lib/ansible/modules/windows/win_domain_group.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ $domain_server = Get-AnsibleParam -obj $params -name "domain_server" -type "str"

$result = @{
changed = $false
created = $false
}

if ($diff_mode) {
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/ansible/modules/windows/win_domain_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,9 @@
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
'''
2 changes: 2 additions & 0 deletions lib/ansible/modules/windows/win_domain_user.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ try {

$result = @{
changed = $false
created = $false
password_updated = $false
}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/ansible/modules/windows/win_domain_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,9 @@
returned: always
type: str
sample: false
created:
description: Whether a user was created
returned: always
type: bool
sample: true
'''
11 changes: 11 additions & 0 deletions test/integration/targets/win_domain_group/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -109,6 +111,7 @@
assert:
that:
- remove_group is changed
- remove_group is not created
- remove_group_actual.rc == 1

- name: remove group again
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a6b7d0d

Please sign in to comment.