• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial 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
6589

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

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.

Related Tutorials in Overview of Ansible Copy Module Part-1

Related Tutorials in Overview of Ansible Copy Module Part-1

How to Create Ansible Playbook to Install Apache Server
How to Create Ansible Playbook to Install Apache Server
May 12, 2021
How to set permissions to the files by using Ansible playbook
How to set permissions to the files by using Ansible playbook
Nov 12, 2021
How to install and configure Ansible on OpenSUSE leap 15.0
How to install and configure Ansible on OpenSUSE leap 15.0
Nov 22, 2018
How to install an application on Windows by using Ansible playbook
How to install an application on Windows by using Ansible playbook
Nov 10, 2021
How to update modified Group Policy on windows by using Ansible playbook
How to update modified Group Policy on windows by using Ansible playbook
Nov 25, 2021
How to configure Windows client setup for Ansible
How to configure Windows client setup for Ansible
Nov 5, 2021
How to set or remove Windows Proxy by using Ansible playbook
How to set or remove Windows Proxy by using Ansible playbook
Nov 9, 2021
Installation and Configuration of Ansible Automation Tool for IT Management
Installation and Configuration of Ansible Automation Tool for IT Management
Jun 16, 2016

Related Forums in Overview of Ansible Copy Module Part-1

Related Forums in Overview of Ansible Copy Module Part-1

Ansible
michael class=
How to Fix “Shared connection to x.x.xx closed” Ansible Error
Nov 6, 2021
Ansible
benjamin class=
How Ansible Ignore errors in tasks and fail at end of the playbook if any tasks had errors
Nov 2, 2021
Python
jacob class=
Ansible “ansible_python_interpreter” Error
Oct 30, 2021
Ansible
niklaus class=
How to install Ansible
Oct 31, 2017
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 Jayce ?
What are the types of table used in IPtables

What are the various types of table used in IPtables and how to use that for my server security?

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.