Since Lookup plugins
Like all templating ... execute and are evaluated on the Ansible Control Machine ...
the env
lookup – Read the value of environment variables
Allows you to query the environment variables available on the Controller when you invoked Ansible.
To gather the environment on the Remote Node it is recommended to gather_facts
about the env
. This will work for Windows Nodes too.
---
- hosts: windows
become: false
gather_facts: true
gather_subset:
- "env"
- "!all"
- "!min"
tasks:
- name: Show Gathered Facts
debug:
msg: "{{ ansible_facts }}"
The answer under Is it possible to gather only specific facts in Ansible? show also how to debug. For a Windows Node it could look like
env:
ALLUSERSPROFILE: "C:\ProgramData"
APPDATA: "C:\Users\ansible-user\AppData\Roaming"
CommonProgramFiles: "C:\Program Files\Common Files"
CommonProgramFiles(x86): "C:\Program Files (x86)\Common Files"
CommonProgramW6432: "C:\Program Files\Common Files"
COMPUTERNAME: "ANSIBLE-WIN"
ComSpec: "C:\WINDOWS\system32\cmd.exe"
DriverData: "C:\Windows\System32\Drivers\DriverData"
GIT_SSH_COMMAND: "C:\\WINDOWS\\System32\\OpenSSH\\ssh.exe"
GIT_SSH_VARIANT: "ssh"
HOMEDRIVE: "H:"
HOMEPATH: "\"
HOMESHARE: "\\dfs.internal.example.com\HomeDirs\Users_1\ansible-user"
LOCALAPPDATA: "C:\Users\ansible-user\AppData\Local"
LOGONSERVER: "\\AD"
NUMBER_OF_PROCESSORS: "16"
OS: "Windows_NT"
Path: "C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPo..."
PATHEXT: ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL"
PROCESSOR_ARCHITECTURE: "AMD64"
PROCESSOR_IDENTIFIER: "AMD64 Family 25 Model 80 Stepping 0, AuthenticAMD"
PROCESSOR_LEVEL: "25"
PROCESSOR_REVISION: "5000"
ProgramData: "C:\ProgramData"
ProgramFiles: "C:\Program Files"
ProgramFiles(x86): "C:\Program Files (x86)"
ProgramW6432: "C:\Program Files"
PSModulePath: "C:\Users\ansible-user\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerSh..."
PUBLIC: "C:\Users\Public"
SESSIONNAME: "Console"
SystemDrive: "C:"
SystemRoot: "C:\WINDOWS"
TEMP: "C:\Users\ansible-user\AppData\Local\Temp"
TMP: "C:\Users\ansible-user\AppData\Local\Temp"
UATDATA: "C:\WINDOWS\CCM\UATData\12345678-90AB-CDEF-0123-4567890ACDEF"
USERDNSDOMAIN: "INTERNAL.EXAMPLE.COM"
USERDOMAIN: "INTERNAL"
USERDOMAIN_ROAMINGPROFILE: "INTERNAL"
USERNAME: "ansible-user"
USERPROFILE: "C:\Users\ansible-user"
windir: "C:\WINDOWS"
After that tasks like
- name: Show Specific Fact
debug:
msg: "{{ ansible_facts.env.USERPROFILE }}"
are possible ans which would provide the requested information.
Since there is almost no documentation available about what is gathered from Windows Remote Nodes, I like to reference the sample data structure from
- Windows Node gathered facts in YAML
- Windows Node gathered facts in JSON
which are from an Ansible playbook that gathers Windows facts using the Ansible setup
module. It shows also in some examples how to work with the facts.