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
471 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 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
77 views
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
217 views
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 1,284 views