• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

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
{{postValue.id}}

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

snap1

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

snap 2

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.

Tags:
vertonskjelvic
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

How does Ansible copy module work?

A

The copy module copies a file from the local or remote machine to a location on the remote machine

Q

How do I copy a Yaml file?

A

Created directories have the same mode as the corresponding source directory, unmodified by the process' unmask. In -R mode, cp will continue copying even if errors are detected.

Q

Where is the inventory file located by default?

A

The inventory file is located by default in /etc/ansible/hosts

Q

How do YAML files work?

A

YAML is a digestible data serialization language often used to create configuration files with any programming language

Q

How do I check my ping in Ansible?

A

To test that Ansible is able to connect and run commands and playbooks on your nodes, you can use the following command: ansible all -m ping.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Ganesh Konka ?
Zentya 6.1 http proxy configuration

please send link for creating zentyal 6.1 for http proxy and firewall as gateway.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.