Directories create twice

Hello !

I have an issue concerning modules find then copy (with relpath filter)

I have a role :

`

  • name: “Test”
    hosts: localhost
    vars:
    archive_name: “/opt/archive.tgz”
    local_tmp_dir:
    path: “/tmp/tmp”
    dest_directory: “”
    tasks:

  • name: “[Module] Download and unarchive module”
    unarchive:
    remote_src: yes
    src: “{{ archive_name }}”
    dest: “{{ local_tmp_dir.path }}”

  • name: “[Module] Recherche de tous les fichiers de la conf”
    find:
    paths: “{{ local_tmp_dir.path }}”
    recurse: yes
    file_type: any
    register: local_modules_files

  • name: “[Module] Deploy module in /”
    copy:
    src: “{{ item.path }}”
    dest: “{{ dest_directory }}/{{ item.path | relpath(local_tmp_dir.path) }}”
    loop_control:
    label: “{{ item.path }}”
    loop: “{{ local_modules_files.files }}”
    `

When I execute it, all seems to works well, but all the directories are create twice and the files existed in all directories (which means that the fs will be full very quickly)
If in the tar I had : /etc/services/service1/script1
It will created :

  • /etc/services/service1/script1 (This one is the good one)
  • /etc/etc/services/service1/script1
  • /etc/services/services/service1/script1
  • /etc/services/service1/service1/script1

Did I miss something ?

without actually looking into it, this does sound very much like a
(missing) trailing slash issue somewhere

Hi, thanks for your response.

I don’t really understand this behavior. It’s probably a syntax error (trailing slash or something like that, as you mentioned)

I ended up using :

`

  • name: “Look for all files in services”
    find:
    paths: “{{ local_tmp_dir.path }}”
    file_type: file
    recurse: yes
    register: local_modules_files

  • debug:
    var: local_modules_files

  • name: “Create directory”
    file:
    path: “{{ ( dest_directory + ‘/’ + ( item.path | relpath(local_tmp_dir.path) ) ) | dirname }}”
    state: directory
    recurse: yes
    loop: “{{ local_modules_files.files }}”

  • name: “Copy”
    copy:
    remote_src: yes
    src: “{{ item.path }}”
    dest: “{{ dest_directory }}/{{ item.path | relpath(local_tmp_dir.path) }}”
    loop: “{{ local_modules_files.files }}”
    `

I looking for file only (not any files type) and I create the subdirectories first then copy files in it (that’s answer my question and seems to be better). I have concern about ownership, but that do what I want to.