Check if a directory exists on Windows-like systems — Ansible module win_stat

How to automate the checking of the “example” directory/folder in the Desktop of the user on the Windows system and display a message or execute a task accordingly with Ansible Playbook.

Ansible Pilot
4 min readMar 15, 2022


How to check if a directory/folder exists on Windows-like systems with Ansible?

I’m going to show you a live demo and some simple Ansible code.

I’m Luca Berton and welcome to today’s episode of Ansible Pilot

Ansible check directory exists on Windows-like systems

  • ``
  • Get information about Windows files

Today we’re talking about the Ansible module `win_stat`.

The full name is ``, which means that is part of the collection of modules specialized to interact with Windows target host.

It’s a module pretty stable and out for years.

It works in Windows and Windows Server operating systems.

It gets information about Windows files.

For Linux target use the `stat` module instead.

Parameters & Return Values

Mandatory Parameters

  • path string

Main Return Values

  • stat complex — isdir

The only mandatory parameter is “path” which is the filesystem full path of the object to check.

The module returns a complex object, the property that is interesting for us is “isdir”. This attribute is “true” if the object is a directory





Ansible Pilot

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday