1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add Windows AD Domain facts for membership and server type (#23500)

* Add Windows Domain facts for membership and server type

Adds additional facts to setup.ps1 for Windows hosts

 * ansible_windows_domain_member - returns true if machine is domain
   joined
 * ansible_windows_domain_role - indicates role of machine in domain

Roles list is taken from
https://technet.microsoft.com/en-us/library/ee198796.aspx and will
return sensible values for non domain joined machines too.

* Use $win32_cs rather than Get-CimInstance Win32_ComputerSystem for consistency
This commit is contained in:
Barney Sowood 2018-01-02 01:20:06 +00:00 committed by ansibot
parent 0a3da471f5
commit 158cd59994

View file

@ -149,6 +149,17 @@ foreach ($item in Get-ChildItem Env:) {
$env_vars.Add($name, $value)
}
$domain_roles = @{
0 = "Stand-alone workstation"
1 = "Member workstation"
2 = "Stand-alone server"
3 = "Member server"
4 = "Backup domain controller"
5 = "Primary domain controller"
}
$domain_role = $domain_roles.Get_Item([Int32]$win32_cs.DomainRole)
$ansible_facts = @{
ansible_architecture = $win32_os.OSArchitecture
ansible_bios_date = $win32_bios.ReleaseDate.ToString("MM/dd/yyyy")
@ -192,6 +203,8 @@ $ansible_facts = @{
ansible_user_id = $env:username
ansible_user_sid = $user.User.Value
ansible_windows_domain = $win32_cs.Domain
ansible_windows_domain_member = $win32_cs.PartOfDomain
ansible_windows_domain_role = $domain_role
# Win32_PhysicalMemory is empty on some virtual platforms
ansible_memtotal_mb = ([math]::round($win32_cs.TotalPhysicalMemory / 1024 / 1024))