Ansible playbbok to copy files from one node to another remote node

0 votes

I'm trying to copy multiple files from one node to another remote node but its very time consuming. Is it possible to automate this using Ansible?

Jan 16, 2019 in Ansible by Jerry
3,819 views

1 answer to this question.

0 votes

You can create a playbook for copying your files from one node to another remote node. 

Use three different modules 

find - that uses patters and looks for the file you need to copy

set fact - sets a variable. These variables will be available to subsequent plays during an ansible-playbook run, but will not be saved across executions even if you use a fact cache.

copy files - this module copies files from one local or remote node to another remote node.

Playbook would look like this:

- name: find pass.Linux*
  find:  paths="/file/path/" recurse=yes patterns=".Linux*"
  register: find_files

- name: set fact
  set_fact:
    all_files:
      - "{{ find_files.files | map(attribute='path') | list }}"
  when: find_files > 0

- name: copy files
  copy:
    src: "{{ item }}"
    dest: /destination/
  with_items: "{{ all_files }}"
  when: find_files > 0
answered Jan 16, 2019 by Danica

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer

How to copy files in remote system using Ansible?

Hi@akhtar, You need to use the copy module ...READ MORE

answered Jul 30, 2020 in Ansible by MD
• 95,440 points
2,071 views
0 votes
1 answer

How to copy multiple files to remote system using Ansible Playbook?

Hi@akhtar, You can use the copy module in ...READ MORE

answered Sep 16, 2020 in Ansible by MD
• 95,440 points
10,291 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,505 views
+2 votes
1 answer
0 votes
1 answer

Ansible playbook for moving files from one node to another remote node

The best way to do this is: copy ...READ MORE

answered Jan 16, 2019 in Ansible by Nigya

edited Jan 18, 2019 by Vardhan 9,259 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP