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.