Ansible win_file Module: Create & Manage Files on Windows (Guide)
By Luca Berton · Published 2024-01-01 · Category: troubleshooting
How to create and manage files on Windows with Ansible win_file module (ansible.windows.win_file). Create files, directories, symlinks on Windows. Practical YAML playbook examples.
How to create an empty file 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 creates an empty file • 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.
Parameters • path path - file path • state string - file/absent/directory/touch
This module has some parameters to perform any 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 "touch" option.
Links • ansible.windows.win_file
Playbook
Create an empty file in Windows-like systems with Ansible playbook
code
execution
idempotency not valid
before execution
after execution
Conclusion
Now you know how to create an empty file in Windows-like systems with Ansible.
Related Articles • Ansible Become Guide • Ansible Inventory Guide • ansible.builtin.file Guide • Ansible for Windows Guide
Category: troubleshooting
Watch the video: Ansible win_file Module: Create & Manage Files on Windows (Guide) — Video Tutorial