Ansible:在模块“copy”中使用正则表达式

Rad*_*FID 5 continuous-integration ansible ansible-playbook ansible-1.x

上下文

我正在尝试构建一个continuous-integration平台,并在 a 中Ansible playbook使用maven-dependency-plugin:get来从masterNexus上的a 下载工件,该工件将使用module部署在远程服务器上。Ansiblecopy

为了制作一个轻量级和通用的剧本,我定义了一个名为的变量app_version,如果定义了,我下载给定的版本,如果没有,我从存储库下载最新版本Nexus。工件下载到给定目录 ( /tmp/delivery/) 中。在我的Ansible任务下面:

- 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/
Run Code Online (Sandbox Code Playgroud)


我的问题

为了确保剧本的通用性,我需要在Ansible模块中编写一个正则表达式copy来选择具有该模式的工件,app*.war但该模块似乎不提供此功能。在我的复制任务下方:

- hosts: agir
  tasks:
    - name: "Copying the war"
      copy: src=/tmp/delivery/app*.war dest=/folder/app.war  owner=user group=group mode=0755
Run Code Online (Sandbox Code Playgroud)

如何在模块中使用正则表达式copy


我正在使用 Ansible 1.8

Kon*_*rov 5

您可以使用:

  - name: "Copying the war"
      copy: src={{item}} dest=/folder/app.war  owner=user group=group mode=0755
      with_fileglob: /tmp/delivery/app*.war
Run Code Online (Sandbox Code Playgroud)

但如果有多个文件怎么办?
我建议注册stdout先前的shell命令并从那里获取文件名(如果可能)。