file - Ansible - 复制是否支持 shell * 扩展

标签 file copy jinja2 ansible

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

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

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

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

最佳答案

您可以使用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/*

关于file - Ansible - 复制是否支持 shell * 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32898515/

相关文章:

python - 在 python 中,如何将文件复制到目录中并在该目录达到一定大小时停止

arrays - 哈希数组元素复制

python - Flask-admin 是否在运行时导入 html 模板?

php - 无法从 PHP 打开文件

c - 如何将一个文件拆分为两个文件以获取 400k 记录

linux - shell 脚本 : Copy directory passed as variable to another directory also as variable passed by user

python - 无效的 block 标记 'else'。您是否忘记注册或加载此标签?

java - 可以使用java从android SD卡读取文件

c - 如何在 C 中读取文件,将二进制缓冲区转换为二进制字符串,然后再次将二进制字符串转换为二进制缓冲区?

python - Flask:蓝图中的模板继承自应用程序中的模板?