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 
    source: /home/ansadmin/test/one.txt 
    dest: /home/ansadmin/test/ 
    - name: "Copy file"
        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.

Leave a Reply

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

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

Facebook photo

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

Connecting to %s