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: –
Script on given Ansible Windows Module
--- - hosts: web tasks: - name: Copy file with owner and permissions win_copy: 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
--- - name: Unarchive a file hosts: web become: yes tasks: - name: Unarchive a file that is already on the remote machine win_unzip: 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.
--- - hosts: web tasks: - 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 win_stat: path: D:\foo.ini register: file_info
Here, it gives the information the file.
--- - hosts: web tasks: - name: Touch a file (creates if not present, updates modification time if present) win_file: 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.