# Directories create twice

**URL:** <https://forum.ansible.com/t/directories-create-twice/32873>\
**Category:** Ansible Project\
**Created:** [May 7, 2020, 9:00am UTC](https://forum.ansible.com/t/directories-create-twice/32873 "2020-05-07T09:00:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quentin\_Aveno](https://avatars.discourse-cdn.com/v4/letter/q/e9c0ed/32.png) [@Quentin\_Aveno](https://forum.ansible.com/u/Quentin_Aveno)\
**Post date:** [May 7, 2020, 9:00am UTC](https://forum.ansible.com/t/directories-create-twice/32873/1 "2020-05-07T09:00:30Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 7, 2020, 9:59am UTC](https://forum.ansible.com/t/directories-create-twice/32873/2 "2020-05-07T09:59:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Quentin\_Aveno](https://avatars.discourse-cdn.com/v4/letter/q/e9c0ed/32.png) [@Quentin\_Aveno](https://forum.ansible.com/u/Quentin_Aveno)\
**Post date:** [May 7, 2020, 11:39am UTC](https://forum.ansible.com/t/directories-create-twice/32873/3 "2020-05-07T11:39:13Z")

</div>

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.
