• 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

Overview of Ansible Copy Module Part-1

  • 01:22 mkdir files
  • 02:40 vim play1.yml
  • 03:00 ansible-playbook polay1.yml
  • 04:30 vim test1.yml
{{postValue.id}}

Overview of Copy Modules in Ansible

Introduction:

Ansible is an agentless computerization tool that can install on a control node. Applying the control node, Ansible runs machines and other devices remotely.

Ansible provides the functionality of copying the files and directories with the help of copy and fetch modules. The copy module is versatile. The copy module is used to copy files and folders from the local machine to the remote servers. And the fetch module to copy data from the remote machine to the local machine. This tutorial will cover the some functions of copy module.

By default ansible search for a file directory in search of any file hence Create a files directory under the ansible.

[root@linuxhelp ansible]# mkdir files

Move into the files directory.

[root@linuxhelp ansible]# cd files

Create the file which you want to copy to your remote location

[root@linuxhelp files]# vim test_files
[root@linuxhelp files]# cd ..

Create a playbook to copy file

[root@linuxhelp ansible]# vim play1.yml

snap1

After completion of playbook lets run the playbook

[root@linuxhelp ansible]# ansible-playbook play1.yml
PLAY [run task on all hosts] ***************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************
ok: [192.168.6.112]
TASK [copy fiel to remote hosts] ***********************************************************************************************************
changed: [192.168.6.112]
PLAY RECAP *********************************************************************************************************************************
192.168.6.112              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Now go to your centos directory and then check file should be copied to that location. snap2 Now to copy multiple files to remote host

Create another file in files directory

[root@linuxhelp ansible]# cd files/
[root@linuxhelp files]# vim test1.txt
[root@linuxhelp files]# cd ..

Since we are creating multiple files copying to remote location so we will use loop in ansible

[root@linuxhelp ansible]# vim play1.yml 

snap3

Now lets run the playbook

[root@linuxhelp ansible]# ansible-playbook play1.yml 
changed: [192.168.6.112] => (item=test1.txt)
PLAY RECAP *********************************************************************************************************************************
192.168.6.112              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
[root@linuxhelp ansible]# vim play1.yml 
[root@linuxhelp ansible]# ansible-playbook play1.yml 
PLAY [run task on all hosts] ***************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************
ok: [192.168.6.112]
TASK [copy fiel to remote hosts] ***********************************************************************************************************
changed: [192.168.6.112] => (item=test_files)
changed: [192.168.6.112] => (item=test1.txt)
PLAY RECAP *********************************************************************************************************************************
192.168.6.112              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
After completion it should copy both file under the HOME directory of our remote location

Now go to the OS centos location and check, now check there should be two files which i copied to remote location snap4 With this method overview of copy module comes to an end.

Tags:
keeljohnston
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is copy module in ansible?

A

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

Q

Can copy module copies recursively?

A

Yes you can copy any directory recursively using copy module.

Q

How to copy multiple files in copy module?

A

To copy multiple files you have to use loop in ansible playbook.

Q

What is difference between copy and fetch module in ansible?

A

The fetch module is used when you want to move files from the remote host to the local host. The copy module is used when you want to put files onto the remote host.

Q

How to do variable interpolation in copied files?

A

You have to use the template module for the variable interpolation.

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 legeek ?
Installation of the call center module

hello

I wish to install a call center in virtual with issabel, I downloaded the latest version of it , but I don' t arrive to install the call center module in issabel. please help me

thanks!

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.