Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Synchronize Not Sourcing Multiple Paths #519

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Axionize
Copy link

SUMMARY

rsync supports sourcing files from multiple paths simply by specifying multiple paths on the command line. When the paths are folders, the same files in subsequent paths will take precedence over those in previous paths. This is often used to "merge" multiple local folders onto a remote.

For example, if this is the folder structure on the local machine and we are copying to /tmp/dest on the remote machine

tmp
├── path_a
│   ├── file1
│   └── file2
├── path_b
│   ├── file2
│   ├── file3
│   └── file4
├── path_c
│   ├── file2
│   └── file5

The result would be

tmp
├── dest
│   ├── file1 ...with data from path_a
│   ├── file2 ...from path_c
│   ├── file3.php ...path_b
│   ├── file4.php ...from path_b
│   └── file5.php ...from path_c

The syntax to do this in ansible is now as follows:

- name: Copy files from multiple folders and merge them into dest
  ansible.posix.synchronize:
    src: 
    - /tmp/path_a/
    - /tmp/path_b/
    - /tmp/path_c/
    dest: /tmp/dest/
    recursive: True

My primary use case for this is having a set of files stored in host_vars, group_vars, and all which should be copied over to the remote with files from host_vars superseding group_vars and group_vars superseding all.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

synchronize

ADDITIONAL INFORMATION

This does not replace specifying a singular path with a string, that still works and thus backwards compatibility is preserved.

The only change this has for existing codebases on end users is in the -vvv debug output and in the invocation args of the variable returned by register:. Specifically var.invocation.module_args.src on synchronize tasks will return a list with 1 entry being the path instead of just the entry, which is unlikely to cause any breakage. If this change in output is unacceptable though, I can spend the effort to modify the modules to use strings and splitting to prevent this.

@maxamillion
Copy link
Collaborator

Closing and re-opening to kick CI.

@maxamillion maxamillion closed this Jan 8, 2024
@maxamillion maxamillion reopened this Jan 8, 2024
Copy link
Contributor

@maxamillion
Copy link
Collaborator

@Axionize can you please rebase on main? I think some of the CI failures aren't valid anymore because they've been fixed in main. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants