# create tepdir and copy file into it?

**URL:** <https://forum.ansible.com/t/create-tepdir-and-copy-file-into-it/27231>\
**Category:** Ansible Project\
**Created:** [April 10, 2018, 2:31pm UTC](https://forum.ansible.com/t/create-tepdir-and-copy-file-into-it/27231 "2018-04-10T14:31:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Renner](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@Michael\_Renner](https://forum.ansible.com/u/Michael_Renner)\
**Post date:** [April 10, 2018, 2:31pm UTC](https://forum.ansible.com/t/create-tepdir-and-copy-file-into-it/27231/1 "2018-04-10T14:31:44Z")

</div>

Moin,

I want to download a file using the maven\_artifact plugin into a temporary directory (an copy this to several other maschines). Now I wonder how to use a registerd variable for this …

- name: create temporary build directory  
tempfile:  
state: directory  
suffix: \_baz

- name : download Artifacts  
maven\_artifact:  
group\_id: “com.foo.bar.baz”  
artifact\_id: “baz-application”  
extension: “war”  
repository\_url: “[http://int-maven-01:8081/nexus/service/local/repositories/releases/content/](http://int-maven-01:8081/nexus/service/local/repositories/releases/content/)”  
validate\_certs: no  
version: “0.0.3”  
username: “”  
password: “”  
dest: “???”

- name: copy war file  
copy:  
src:???  
dest: /opt/tomcat/webapp/  
owner: tomcat  
group: root  
mode: 0440

How do I get the name of the directory? How can I use this to the dest and src fields?

Thanks

---

<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:** [April 10, 2018, 3:41pm UTC](https://forum.ansible.com/t/create-tepdir-and-copy-file-into-it/27231/2 "2018-04-10T15:41:54Z")

</div>

> Moin,
> 
> I want to download a file using the maven\_artifact plugin into a temporary  
> directory (an copy this to several other maschines). Now I wonder how to  
> use a registerd variable for this .....
> 
> &nbsp;&nbsp;- name: create temporary build directory  
> &nbsp;&nbsp;&nbsp;&nbsp;tempfile:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: directory  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;suffix: \_baz

&nbsp;&nbsp;- name: create temporary build directory  
&nbsp;&nbsp;&nbsp;&nbsp;tempfile:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: directory  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;suffix: \_baz  
&nbsp;&nbsp;&nbsp;&nbsp;register: tmpdir  
&nbsp;&nbsp;&nbsp;&nbsp;run\_once: yes  
&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: localhost

If I understand you correctly you want to download to localhost, and then copy it out to all the host in the play.  
If so you need to add run\_once and delegate\_to.

> &nbsp;&nbsp;- name : download Artifacts  
> &nbsp;&nbsp;&nbsp;&nbsp;maven\_artifact:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;group\_id: "com.foo.bar.baz"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;artifact\_id: "baz-application"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;extension: "war"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;repository\_url:  
> "[http://int-maven-01:8081/nexus/service/local/repositories/releases/content/&quot](http://int-maven-01:8081/nexus/service/local/repositories/releases/content/&quot);  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;validate\_certs: no  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version: "0.0.3"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username: ""  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password: ""  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: "???"

&nbsp;&nbsp;dest: "{{ tmpfile.path }}"

> &nbsp;&nbsp;- name: copy war file  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copy:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src:???  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /opt/tomcat/webapp/  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;owner: tomcat  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;group: root  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mode: 0440

&nbsp;&nbsp;src: "{{ tmpfile.path }}/"

The slash at the end is important since it means content of directory.

> How do I get the name of the directory? How can I use this to the dest and  
> src fields?

You register the output to a variable, and then this variable contain .path with the content of the temporary directory.

---

<div class="post-metadata">

**Author:** ![Michael\_Renner](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@Michael\_Renner](https://forum.ansible.com/u/Michael_Renner)\
**Post date:** [April 11, 2018, 1:34pm UTC](https://forum.ansible.com/t/create-tepdir-and-copy-file-into-it/27231/3 "2018-04-11T13:34:37Z")

</div>

Moin,

[…]

> If I understand you correctly you want to download to localhost, and then copy it out to all the host in the play.  
> If so you need to add run\_once and delegate\_to. you need to add run\_once and delegate\_to

[…]

CU
