create tepdir and copy file into it?

129 views
Skip to first unread message

Michael Renner

unread,
Apr 10, 2018, 10:31:44 AM4/10/18
to Ansible Project
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/"
      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

Kai Stian Olstad

unread,
Apr 10, 2018, 11:42:07 AM4/10/18
to ansible...@googlegroups.com
On Tuesday, 10 April 2018 16.31.44 CEST Michael Renner wrote:
> 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: create temporary build directory
tempfile:
state: directory
suffix: _baz
register: tmpdir
run_once: yes
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.

>
> - 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/"
> validate_certs: no
> version: "0.0.3"
> username: ""
> password: ""
> dest: "????"

dest: "{{ tmpfile.path }}"


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

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.


--
Kai Stian Olstad

Michael Renner

unread,
Apr 11, 2018, 9:34:37 AM4/11/18
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages