How to extract a downloaded file on windows by using the Ansible playbook
To Extract a Downloaded file on Windows by using Ansible Playbook
Introduction:
Ansible is an automatic configuration tool used in wide range of windows and UNIX like systems. win_unzip is the module which is used for manage Achieved files.
Master Server Requirements:
• ansible
• python3-pip
• pywinrm (python package)
Windows Requirements:
• powershell 3+
• Dot net 4
Installation Procedure:
Step 1: Check the OS version by using the below command
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 21.04
Release: 21.04
Codename: hirsute
Step 2: Check the availability of Ansible package by using the below command
root@linuxhelp:~# apt list -a ansible
Listing... Done
ansible/hirsute,hirsute,now 4.8.0-1ppa~hirsute all [installed]
ansible/hirsute,hirsute 2.10.7-1 all
Step 3: Check the availability of python3-pip package by using the below command
root@linuxhelp:~# apt list -a python3
Listing... Done
python3/hirsute,now 3.9.4-1 amd64 [installed,automatic]
python3/hirsute 3.9.4-1 i386
Step 4: Check the availability of python package pywinrm by using the below command
root@linuxhelp:~# pip list | grep pywinrm
pywinrm 0.4.2
Step 5: Create inventory for Windows node system by using the below command
root@linuxhelp:~# vi /etc/ansible/hosts
[windows]
192.168.6.104
[windows:vars]
ansible_user=Admin
ansible_password=Admin@123
ansible_port=5986
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
Step 6: Create a playbook in the name of test.yml by using the below command
root@linuxhelp:~# vi test.yml
- hosts: windows
gather_facts: true
tasks:
- name: Copy the zip file
win_get_url:
url: ftp://192.168.7.150/Operating-system/WINDOWS/group-policy/with-modification.zip
url_username: ftpadmin
url_password: sys#ad$004
dest: E:\Apps
- name: Extracting Files
win_unzip:
src: E:\Apps\with-modification.zip
dest: C:\Windows\System32\GroupPolicy
Step 7: Check the destination folder as shown in the below image

Step 8: Check the syntax of the test.yml ansible playbook by using the below command
root@linuxhelp:~# ansible-playbook test.yml --syntax-check
playbook: test.yml
Step 9: Run the test.yml playbook by using the below command
root@linuxhelp:~# ansible-playbook test.yml
PLAY [windows] *******************************************************************************************
TASK [Gathering Facts] ***********************************************************************************
ok: [192.168.6.104]
TASK [Copy the zip file] *********************************************************************************
changed: [192.168.6.104]
TASK [Extracting Files] **********************************************************************************
changed: [192.168.6.104]
PLAY RECAP ***********************************************************************************************
192.168.6.104 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Step 10: The files are extracted in the destination folder by ansible playbook as shown in the below image.

By this to extract a downloaded file on windows by using Ansible playbook has been completed.
Comments ( 0 )
No comments available