# unable to create directory

**URL:** <https://forum.ansible.com/t/unable-to-create-directory/26235>\
**Category:** Ansible Project\
**Created:** [December 9, 2017, 5:14am UTC](https://forum.ansible.com/t/unable-to-create-directory/26235 "2017-12-09T05:14:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [December 9, 2017, 5:14am UTC](https://forum.ansible.com/t/unable-to-create-directory/26235/1 "2017-12-09T05:14:14Z")

</div>

I am trying to clone a git repository using the git clone command but it is unable to create the directory structure and copies the entire files in the parent directory.  
example when i do the

- git: repo=[http://pathtothegit/container.git](http://pathtothegit/container.git) dest=/data/config recursive=yes ====\> it only copies the files to the /data/config directory it doesnot make the directory container under /data/config like /data/config/container rather copies all the files under /data/config ( not under /data/config/container/)

Could you please let me know if i need to mention anything in the git module…thanks for the help…

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [December 9, 2017, 9:43am UTC](https://forum.ansible.com/t/unable-to-create-directory/26235/2 "2017-12-09T09:43:17Z")

</div>

> I am trying to clone a git repository using the git clone command but it is  
> unable to create the directory structure and copies the entire files in the  
> parent directory.  
> example when i do the  
> - git: repo=[http://pathtothegit/container.git](http://pathtothegit/container.git) dest=/data/config  
> recursive=yes ====\> it only copies the files to the /data/config directory  
> it doesnot make the directory container under /data/config like  
> /data/config/container rather copies all the files under /data/config ( not  
> under /data/config/container/)
> 
> Could you please let me know if i need to mention anything in the git  
> module...thanks for the help..

That's just how Git and the Git module work.

As the Ansible documentation for Git module state:  
dest -\> The path of where the repository should be checked out.

Ansible is running  
git clone [http://pathtothegit/container.git](http://pathtothegit/container.git) /data/config

If you do that on the command line you'll get the same result.

> From the man git:

git clone \<repository\> [\<directory\>]

\<directory\>  
&nbsp;&nbsp;The name of a new directory to clone into. The "humanish" part of the  
&nbsp;&nbsp;source repository is used if no directory is explicitly given  
&nbsp;&nbsp;(repo for /path/to/repo.git and foo for host.xz:foo/.git). Cloning into  
&nbsp;&nbsp;an existing directory is only allowed if the directory is empty.

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [December 9, 2017, 5:20pm UTC](https://forum.ansible.com/t/unable-to-create-directory/26235/3 "2017-12-09T17:20:07Z")

</div>

Thanks for replying Kai, if i understand you correctly , git module in anisble doesnot create the parent directory for example if the playbook has the below git play  
git: repo= git: repo=[https://github.com/drush-ops/drush.git](https://github.com/drush-ops/drush.git) dest=/data/gitfiles clone=yes ==\> it will not create a drush directory under /data/gitfiles…

and only when we run @command prompt #git clone [https://github.com/drush-ops/drush.git](https://github.com/drush-ops/drush.git) , it will create a directory drush under the present working directory as there was no directory mention…so there is no way that we have that directory “drush” created under the directory …thanks for the help.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [December 9, 2017, 5:32pm UTC](https://forum.ansible.com/t/unable-to-create-directory/26235/4 "2017-12-09T17:32:01Z")

</div>

> Thanks for replying Kai, if i understand you correctly , git module in  
> anisble doesnot create the parent directory for example if the playbook has  
> the below git play  
> git: repo= git: repo=[https://github.com/drush-ops/drush.git](https://github.com/drush-ops/drush.git)  
> dest=/data/gitfiles clone=yes ==\> it will not create a drush directory  
> under /data/gitfiles...

Well, it sort of does, it will create /data/gitfiles if it doesn't exist, but i doesn't append a directory to dest.

> and only when we run @command prompt #git clone  
> [https://github.com/drush-ops/drush.git](https://github.com/drush-ops/drush.git) , it will create a directory drush  
> under the present working directory as there was no directory mention...so  
> there is no way that we have that directory "drush" created under the  
> directory ...thanks for the help.

Correct, that a feature of git command line tool.  
If you set dest to /data/gitfiles/drush you'll get what you are looking for.  
The git-module will create the drush directory if it doesn't exist.

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [December 9, 2017, 6:06pm UTC](https://forum.ansible.com/t/unable-to-create-directory/26235/5 "2017-12-09T18:06:19Z")

</div>

thanks again Kai for that insight…

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [December 9, 2017, 6:13pm UTC](https://forum.ansible.com/t/unable-to-create-directory/26235/6 "2017-12-09T18:13:40Z")

</div>

also anytime if need to run the clone multiple times then can we use the force command …to get the updated repo…
