How to copy files and folders in windows by using Ansible Playbook on Oracle Linux 8.5
- 00:35 cat /etc/os-release
- 00:50 yum list ansible
- 01:04 yum list python3
- 01:21 pip3 list | grep pywinrm
- 01:45 vim /etc/ansible/hosts
- 02:39 vim file.yml
- 04:19 ansible-playbook file.yml --syntax-check
- 04:41 ansible-playbook file.yml
- 05:21 vim folder.yml
- 06:56 ansible-playbook folder.yml --syntax-check
- 07:09 ansible-playbook folder.yml
To Copy File And Folder In Windows By using Ansible Playbook On Oracle Linux 8.5
Introduction:
The Ansible playbook is a set of scripts that define the work to be done by the automation tool Ansible to configure a server.By using win_copy, you can copy a local file to a remote location.
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 ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="8.5"
ID="ol"
ID_LIKE="fedora"
Step 2: Check the availability of Ansible package, python3-pip package, pywinrm by using the below command
[root@linuxhelp ~]# yum list ansible
ansible.noarch 2.9.27-1.el8 @ol8_developer_EPEL
Available Packages
ansible.src 2.9.27-1.el8 ol8_developer_EPEL
[root@linuxhelp ~]# yum list python3
Last metadata expiration check: 1:28:13 ago on Sun 11 Sep 2022 03:22:41 PM IST.
Available Packages
python3.src 3.6.8-45.0.1.el8 ol8_baseos_latest
python3.src 3.6.8-45.0.1.el8 ol8_appstream
[root@linuxhelp ~]# pip3 list | grep pywinrm
pywinrm (0.4.3)
Step 3: Create inventory for Windows node system by using the below command
[root@linuxhelp ~]# vim /etc/ansible/hosts
[windows]
192.168.6.51
[windows:vars]
ansible_user=Admin
ansible_password=Linuxc#4
ansible_port=5986
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
Step 4: Create a playbook to copy a file by using the below command
root@linuxhelp:~# vim file.yml
---
- hosts: windows
tasks:
- name: Copy File
win_copy:
src: F:\fusionpbx-docs.pdf
dest: C:\Ansible\
remote_src: yes
Step 5: Check the syntax of the file.yml ansible playbook by using the below command
root@linuxhelp:~# ansible-playbook file.yml --syntax-check
playbook: file.yml
Step6: Run the file.yml playbook by using the below command
[root@linuxhelp ~]# ansible-playbook file.yml
PLAY [windows] ************************************************************************
TASK [Gathering Facts] ****************************************************************
ok: [192.168.6.51]
TASK [Copy File] **********************************************************************
changed: [192.168.6.51]
PLAY RECAP ****************************************************************************
192.168.6.51 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Step 7: Check in Windows whether the file has been copied as shown in the below image

Step 8: Create a playbook to copy a folder by using the below command
[root@linuxhelp ~]# vim folder.yml
Step 9: Check the syntax of the folder.yml ansible playbook by using the following command
[root@linuxhelp ~]# ansible-playbook folder.yml --syntax-check
playbook: folder.yml
Step 10: Run the folder.yml playbook by using the below command
[root@linuxhelp ~]# ansible-playbook folder.yml
PLAY [windows] ************************************************************************
TASK [Gathering Facts] ****************************************************************
ok: [192.168.6.51]
TASK [Copy Folder] ********************************************************************
changed: [192.168.6.51]
PLAY RECAP ****************************************************************************
192.168.6.51 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Step 11: Check in windows whether the folder has been copied as shown in the below image

Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to copy file and folder in windows by using Ansible Playbook on Oracle Linux 8.5. Your feedback is much welcome.
Comments ( 0 )
No comments available