Ansible Playbook to copy files from one server to other

In the previous post we have seen how to write Ansible Playbook, In this post we will be seeing how we can copy files from one server to other using Ansible copy module.

You can read about the module here.

So let’s get started, Create a file with the name copyplaybook.yml and write the below contents.

- name: "Copy files" 
  hosts: db 
  become: yes 
  gather_facts: false 
  vars: 
    source: /home/ansadmin/test/one.txt 
    dest: /home/ansadmin/test/ 
  tasks: 
    - name: "Copy file"
      copy:
        src: "{{source}}"
        dest: "{{dest}}"
        owner: ansadmin
        group: root
        mode: 777 

Here we are using copy module to copy file from one server to other.

Apart from this we’ve also touched upon a concept called variables, where we have defined variables in “vars” and then using the same in src and dest.



Categories: Ansible, DevOps

Tags: , , , ,

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: