forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
win_domain_membership: added better error handling and basic tests (a…
- Loading branch information
Showing
4 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
windows/ci/group2 |
20 changes: 20 additions & 0 deletions
20
test/integration/targets/win_domain_membership/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
- name: get current workgroup | ||
win_shell: (Get-WmiObject Win32_ComputerSystem).Workgroup | ||
register: workgroup | ||
|
||
- name: fail if workgroup result is empty (means test host is in a domain) | ||
fail: | ||
msg: Cannot run tests for win_domain_membership when host is a member of a domain | ||
when: workgroup.stdout == "" | ||
|
||
- block: | ||
- include_tasks: tests.yml | ||
|
||
always: | ||
- name: revert workgroup back to original before tests | ||
win_domain_membership: | ||
workgroup_name: '{{workgroup.stdout_lines[0]}}' | ||
state: workgroup | ||
domain_admin_user: fake user | ||
domain_admin_password: fake password |
59 changes: 59 additions & 0 deletions
59
test/integration/targets/win_domain_membership/tasks/tests.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
- name: change workgroup (check mode) | ||
win_domain_membership: | ||
workgroup_name: ANSIBLETEST | ||
state: workgroup | ||
domain_admin_user: fake user | ||
domain_admin_password: fake password | ||
register: change_workgroup_check | ||
check_mode: yes | ||
|
||
- name: get result of change workgroup (check mode) | ||
win_shell: (Get-WmiObject Win32_ComputerSystem).Workgroup | ||
register: change_workgroup_result_check | ||
|
||
- name: assert result of change workgroup (check mode) | ||
assert: | ||
that: | ||
- change_workgroup_check|changed | ||
- change_workgroup_result_check.stdout == workgroup.stdout | ||
|
||
- name: change workgroup | ||
win_domain_membership: | ||
workgroup_name: ANSIBLETEST | ||
state: workgroup | ||
domain_admin_user: fake user | ||
domain_admin_password: fake password | ||
register: change_workgroup | ||
|
||
- name: get result of change workgroup | ||
win_shell: (Get-WmiObject Win32_ComputerSystem).Workgroup | ||
register: change_workgroup_result | ||
|
||
- name: assert result of change workgroup | ||
assert: | ||
that: | ||
- change_workgroup|changed | ||
- change_workgroup_result.stdout_lines[0] == "ANSIBLETEST" | ||
|
||
- name: change workgroup (idempotent) | ||
win_domain_membership: | ||
workgroup_name: ANSIBLETEST | ||
state: workgroup | ||
domain_admin_user: fake user | ||
domain_admin_password: fake password | ||
register: change_workgroup_again | ||
|
||
- name: assert result of change workgroup (idempotent) | ||
assert: | ||
that: | ||
- not change_workgroup_again|changed | ||
|
||
- name: change workgroup fail invalid name | ||
win_domain_membership: | ||
workgroup_name: ANSIBLELONGNAMEFAILURE | ||
state: workgroup | ||
domain_admin_user: fake user | ||
domain_admin_password: fake password | ||
register: fail_change_workgroup | ||
failed_when: "fail_change_workgroup.msg != 'failed to set workgroup through WMI, return value: 2695'" |