Look at Windows Module of Ansible

Reading Time: 2 minutes

Hello Everyone! Today we will learn how we can create Windows Module in Ansible.

When using Ansible to manage Windows, many of the syntax and rules that apply for Unix/Linux hosts also apply to Windows, but there are still some differences when it comes to components like path separators and OS-specific tasks. This document covers details specific to using Ansible for Windows.

Some of the Windows Modules used in Ansible: –

  • win_copy
  • win_file
  • win_command
  • win_stat
  • win_unzip

Script on given Ansible Windows Module

  1. win_copy
- hosts: web
    - name: Copy file with owner and permissions
        src: ./commands.txt
        dest: C:\Users\Administrator\Downloads\

Here, “src” contains the current working directory which stores “commands.txt” file that is going to be copied on the Destination path

2. win_unzip

- name: Unarchive a file
  hosts: web
  become: yes
  - name: Unarchive a file that is already on the remote machine
      src: /Downloads/mysql-server_8.0.22-1debian10_amd64.deb-bundle.tar
      dest: /Downloads/
      remote_src: yes

Here, “src” contains the current working directory which stores “sql package” that needs to unzip/unarchive on the Destination path.

3. win_command

- hosts: web
   - name: Run command to create a folder
     win_command: cmd.exe /c mkdir C:\test

Here, the command consists of creating new directory in the give path.


- name: Obtain information about a file
    path: D:\foo.ini
  register: file_info

Here, it gives the information the file.

5. win_file

- hosts: web
  - name: Touch a file (creates if not present, updates modification time if present)
      path: D:\file.txt
      state: touch

Here, it will create a file when it is not present on the given path.

Apart, from the given modules above there are more modules which are given in the official document.

Modules in Ansible can also be created by the developer also. For more information click.

References :



Written by 

VIkas Vashisth is a Software Consultant and having experience in DevOps. He loves to know about new technology.