fix Windows tests with hardcoded Administrator account (#35339)

* Admin account is not always called Administrator (eg Azure)
* this fixes some, but not all issues related to the Administrator account on non-English Windows as well (still numerous references to "Administrators" and other en-US Windows group names)
This commit is contained in:
Matt Davis 2018-01-25 02:56:58 -08:00 committed by GitHub
commit 2a9ec6bdbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 103 additions and 58 deletions

View file

@ -1,4 +1,12 @@
---
- name: Look up built-in Administrator account name (-500 user whose domain == computer name)
raw: $machine_sid = (Get-CimInstance Win32_UserAccount -Filter "Domain='$env:COMPUTERNAME'")[0].SID -replace '(S-1-5-21-\d+-\d+-\d+)-\d+', '$1'; (Get-CimInstance Win32_UserAccount -Filter "SID='$machine_sid-500'").Name
check_mode: no
register: admin_account_result
- set_fact:
admin_account_name: "{{ admin_account_result.stdout_lines[0] }}"
- name: ensure task is deleted before test
win_scheduled_task:
name: '{{test_scheduled_task_stat_name}}'
@ -34,7 +42,7 @@
name: '{{test_scheduled_task_stat_name}}'
state: present
logon_type: interactive_token
username: Administrator
username: '{{ admin_account_name }}'
author: Ansible Author
description: Fake description
execution_time_limit: PT23H
@ -102,7 +110,7 @@
- stat_task_present.principal.group_id == None
- stat_task_present.principal.logon_type == "TASK_LOGON_INTERACTIVE_TOKEN"
- stat_task_present.principal.run_level == "TASK_RUNLEVEL_LUA"
- stat_task_present.principal.user_id.endswith("Administrator")
- stat_task_present.principal.user_id.endswith(admin_account_name)
- stat_task_present.registration_info.author == "Ansible Author"
- stat_task_present.registration_info.date is defined
- stat_task_present.registration_info.description == "Fake description"