Ansible - 复制支持shell *扩展

时间:2015-10-01 23:48:58

标签: file copy jinja2 ansible ansible-playbook

Ansible 1.9.2 /更新。

剧本:

# Push Performance tests artifact zip file on remote jmeter machine
- name: Push Performance tests artifact zip file on remote jmeter machine
  copy: src="performance-tests-*.zip"  dest={{ common_download_dir }} 

出错:

19:32:08 TASK: [perf_tests | Push Performance tests artifact zip file on remote jmeter machine] *** 
19:32:08 fatal: [jmeter01.server.in.vcloud] => input file not found at /home/service/workspace/run-project-performance-tests/build/artifacts/roles/perf_tests/files/performance-tests-*.zip or /home/service/workspace/run-project-performance-tests/build/artifacts/performance-tests-*.zip
19:32:08 
19:32:08 FATAL: all hosts have already failed -- aborting

我检查了源计算机(我正在运行ansible),工作区有有效文件:performance-tests-0.0.8-20151001.232123-11.zip

copy: src="somePath/*.zip" dest="somePathOnRemoteMachine"复制操作期间,是不是ansible支持shell扩展,即src =参数(在所有文件中)?

Ansible网站上的所有示例:https://docs.ansible.com/ansible/copy_module.html仅显示 src = ... 参数的一个文件。

PS :我没有在复制模块中使用验证参数。

2 个答案:

答案 0 :(得分:2)

您可以使用http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-fileglobs with_fileglob匹配单个目录中的所有文件,非递归地匹配模式。它可以像这样使用::

# copy each file over that matches the given pattern
- copy: src={{ item }} dest=/etc/fooapp/ owner=root mode=600
  with_fileglob:
    - /playbooks/files/fooapp/*

答案 1 :(得分:1)

没有。

我想最简单的方法是使用shell模块,并直接发出cp命令。