AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Create Directories in Windows Systems Using Ansible

By Luca Berton · Published 2024-01-01 · Category: troubleshooting

Master directory creation on Windows systems with Ansible’s win_file module. Follow our live Playbook example for efficient directory management.

How to create a directory in Windows-like systems with Ansible?

I'm going to show you a live Playbook and some simple Ansible code. I'm Luca Berton and welcome to today's episode of Ansible Pilot

Ansible create a directory

> ansible.windows.win_file Creates, touches, or removes files or directories

Today we're talking about the Ansible module win_file. The full name is ansible.windows.win_file, which means that is part of the collection of modules to interact with windows machines. It's a module pretty stable and out for years. It creates, touches, or removes files or directories. For Linux targets, use the ansible.builtin.file module instead

Main Parameters • path path - file path • state string - file/absent/directory/touch

This module has some parameters to perform different tasks. The only required is "path", where you specify the filesystem path of the file you're going to edit. The state defines the type of object we are modifying, the default is "file" but for our use case, we need the "directory" option.

Linksansible.windows.win_file

## Playbook

How to create an "example" directory/folder in the Desktop of the user on Windows-like systems with Ansible Playbook.

code

execution

idempotency

before execution

!win_file before execution

after execution

!win_file after execution

code with ❤️ in GitHub

Conclusion

Now you know how to create a directory in Windows-like systems with Ansible.

Related ArticlesAnsible Inventory Guideansible.builtin.file GuideAnsible for Windows Guide

Category: troubleshooting

Watch the video: Create Directories in Windows Systems Using Ansible — Video Tutorial

Browse all Ansible tutorials · AnsiblePilot Home