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 in Ansible by Jerry
41 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 by Danica

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer

Trying to execute bash script using Ansible one one node

You could make your task an asynchronous action by ...READ MORE

answered Jan 28 in Ansible by Kavya
40 views
0 votes
1 answer

copy multiple files to multiple systems - Ansible

You can use /usr/bin/ansible command line. Ansible can SCP ...READ MORE

answered Mar 6 in Ansible by Yogesh
49 views
+13 votes
2 answers
0 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 in Ansible by Nigya

edited Jan 18 by Vardhan 335 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.