I'm trying to build a continuous-integration
platform and in a Ansible
playbook
I use the maven-dependency-plugin:get
to download an artifact from a Nexus
on the master which will be deployed on a remote server using the Ansible
module copy
.
In order to make a lightweight and generic playbook, I defined a variable called app_version
that, if it's defined, I download the given version and if not I download the Latest version from the Nexus
repository. The artifact is downloaded in a given directory (/tmp/delivery/
). Below my Ansible
task:
- hosts: local
tasks:
- name: "Downloading the war"
shell: >
mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:get -DgroupId=App-DartifactId=App-Dversion={{ app_version if app_version is defined else 'LATEST' }} -Dpackaging=war -DrepositoryId=my-nexus -Ddest=/tmp/delivery/
To assure the playbook genericity, I need to write a regular expression in the Ansible
module copy
to pick the artifact having the pattern app*.war
but it looks like the module don't provide this ability. Below my copy tastk:
- hosts: agir
tasks:
- name: "Copying the war"
copy: src=/tmp/delivery/app*.war dest=/folder/app.war owner=user group=group mode=0755
How can I use a regular expression in the module copy
?
I'm using Ansible 1.8
You can use:
- name: "Copying the war"
copy: src={{item}} dest=/folder/app.war owner=user group=group mode=0755
with_fileglob: /tmp/delivery/app*.war
But what if there are more than one file?
I would recommend to register stdout
of previous shell
command and get filename from there if possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With