From 8d5cebd59704cb33bf820eb96ee2fcd047cf3e52 Mon Sep 17 00:00:00 2001
From: Hillel Antonov <dev.antonov.hillel@dev.bwater.com>
Date: Tue, 15 Dec 2015 10:43:33 -0500
Subject: [PATCH] Adding gathering environment variables to gather facts on
 Windows making similar in functionality to gather facts on Linux

---
 lib/ansible/modules/windows/setup.ps1 | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/ansible/modules/windows/setup.ps1 b/lib/ansible/modules/windows/setup.ps1
index c60e8f3b9d..fcac689b1e 100644
--- a/lib/ansible/modules/windows/setup.ps1
+++ b/lib/ansible/modules/windows/setup.ps1
@@ -81,6 +81,16 @@ $ips = @()
 Foreach ($ip in $netcfg.IPAddress) { If ($ip) { $ips += $ip } }
 Set-Attr $result.ansible_facts "ansible_ip_addresses" $ips
 
+$env_vars = New-Object psobject
+foreach ($item in Get-ChildItem Env:)
+{
+    $name = $item | select -ExpandProperty Name
+    # Powershell ConvertTo-Json fails if string ends with \
+    $value = ($item | select -ExpandProperty Value).TrimEnd("\")
+    Set-Attr $env_vars $name $value
+}
+Set-Attr $result.ansible_facts "ansible_env" $env_vars
+
 $psversion = $PSVersionTable.PSVersion.Major
 Set-Attr $result.ansible_facts "ansible_powershell_version" $psversion