11

With the following task

- name: synchronising ...
  synchronize: src=files/to/synchronize dest=/tmp/1

the files/to/synchronize directory is synchronized, and after it's done there is a /tmp/1/synchronize directory on the target machine.

Is it possible to use the syncrhonize task to recursively synchronize only contents of the source directory, so that all its contents was in the /tmp/1 without extra level of depth?

What I've done:

  • I went through documentation
  • I tried to google
  • I went through ansible synchronize module source
Falcon Momot
  • 25,244
  • 15
  • 63
  • 92
zerkms
  • 431
  • 2
  • 5
  • 17
  • 2
    Try adding a trailing slash to the source directory, ie `src=files/to/synchronize/`. As for the downvote, mouse over the down arrow; the popup says "*This question does not show any research effort; it is unclear or not useful*". Downvotes without comment may be presumed to be for at least one of those reasons. – MadHatter Sep 09 '15 at 06:00
  • take a look at the documentation. `dirs=yes` parameter (_Transfer directories without recursing_) might be what you are looking for. – Henrik Pingel Sep 09 '15 at 06:15

2 Answers2

27

All you need to do is add a trailing slash to the end of the source path. This will tell Ansible it is the files in the directory, and not the directory and its contents, that you want to transfer.

This behaviour is identical to that of rsync.

Falcon Momot
  • 25,244
  • 15
  • 63
  • 92
  • 1
    Slash did the job, and wildcard turns it into "file not found" - there is no shell to expand it. Thanks. Is there an official explanation for the behaviour? – zerkms Sep 09 '15 at 06:17
  • 1
    I don't think there is a reference... This is just the way such commands work by convention. I am not sure if it is in POSIX anywhere but it might be. – Falcon Momot Sep 09 '15 at 06:19
  • 2
    Yes, and it's in the `rsync` man page ("*A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination*"). You may or may not wish to see some linkage between your not finding that in your extensive research phase and the downvotes you complain so loudly about. – MadHatter Sep 09 '15 at 06:20
  • 1
    @zerkms No. In your question *as originally written* you gave no indication of what work, if any, you had done on the question before answering it. That, coupled with a basic spelling error in the title, didn't speak well of its quality, and (possibly because of that) it started collecting downvotes. Now, you've improved the question, we've fixed the spelling error, and no more downvotes are appearing. **This is the system working as it should.** You might want to relax a little! – MadHatter Sep 09 '15 at 06:46
  • `s/answering it/asking it/ # my bad!` – MadHatter Sep 09 '15 at 07:34
  • @zerkms not by me; only a moderator can do that. Seriously, please consider what that says about how your argument is seen, step back and have a cup of tea, and relax. Continuing to chase this issue may not end well. – MadHatter Sep 09 '15 at 07:40
  • @zerkms the discussion here would be better served by meta.serverfault.com. – Falcon Momot Sep 09 '15 at 07:40
  • @FalconMomot I completely agree, and had posted a comment to that effect (which I edited away when zerkms' comment was removed, because it looked odd in isolation). Me, I'd advise against escalating it to meta, but it's his/her right, and it's definitely the appropriate forum for this issue. – MadHatter Sep 09 '15 at 07:42
0

example of coping only the content current directory to the remote one:

- name: copy project to remote location
  synchronize:
   src: "./"
   dest: "/better_spots"
andilabs
  • 105
  • 4