Ansible从列表创建带有存档模块的tar.gz
我试图在Ansible中查找超过一天的文件,然后创建这些文件的tar.gz,我尝试了Ansible从列表创建带有存档模块的tar.gz,ansible,Ansible,我试图在Ansible中查找超过一天的文件,然后创建这些文件的tar.gz,我尝试了archive模块,尽管它只创建列表中最后一个元素的tar。有没有办法创建包含所有文件的tar.gz 以下是我的脚本: - name: Check all files find: paths=/myfiles file_type=file age=1 age_stamp=mtime register: files failed
archive
模块,尽管它只创建列表中最后一个元素的tar。有没有办法创建包含所有文件的tar.gz
以下是我的脚本:
- name: Check all files
find: paths=/myfiles
file_type=file
age=1
age_stamp=mtime
register: files
failed_when: files.matched < 10
- name: Remove previous tarFile
file: path=/tmp/test.tar.gz
state=absent
- name: compress all the files in tar.gz
archive: path="{{ item.path }}"
dest=/tmp/test.tar.gz
format=gz
with_items:
"{{ files.files }}"
-名称:检查所有文件
查找:路径=/myfiles
文件类型=文件
年龄=1
年龄戳=mtime
注册:文件
当:files.matched<10时失败
-名称:删除以前的tar文件
文件:path=/tmp/test.tar.gz
状态=缺席
-名称:压缩tar.gz中的所有文件
存档:path=“{item.path}}”
dest=/tmp/test.tar.gz
格式=gz
有以下项目:
“{{files.files}}”
它只创建列表中最后一个元素的tar
它正在为循环中的每个文件创建和覆盖/tmp/test.tar.gz
。当你检查时,你只看到最后一个
如果您查看,您将看到:
path
Remote absolute path、glob或要压缩或归档的一个或多个文件的路径列表
因此,您可以提供文件列表作为path
参数的值:
- name: compress all the files in tar.gz
archive:
path: "{{ files_to_archive }}"
dest: /tmp/test.tar.gz
format: gz
vars:
files_to_archive: "{{ files.files | map(attribute='path') | list }}"
它只创建列表中最后一个元素的tar
它正在为循环中的每个文件创建和覆盖/tmp/test.tar.gz
。当你检查时,你只看到最后一个
如果您查看,您将看到:
path
Remote absolute path、glob或要压缩或归档的一个或多个文件的路径列表
因此,您可以提供文件列表作为path
参数的值:
- name: compress all the files in tar.gz
archive:
path: "{{ files_to_archive }}"
dest: /tmp/test.tar.gz
format: gz
vars:
files_to_archive: "{{ files.files | map(attribute='path') | list }}"
我使用下面的方法创建了多个zip文件 - name: 'Create zip archive of {{ date_input }} NMON HTML files' archive: path: /tmp/{{ inventory_hostname }}_*.html dest: /tmp/NMON-{{ inventory_hostname }}.zip format: zip when: option == "5" delegate_to: localhost -名称:'创建{date\u input}}NMON HTML文件的zip存档' 档案文件: 路径:/tmp/{{inventory\u hostname}}}.*.html dest:/tmp/NMON-{inventory\u hostname}}.zip 格式:zip 时间:选项==“5” 委托给:localhost
我使用下面的方法创建了多个zip文件 - name: 'Create zip archive of {{ date_input }} NMON HTML files' archive: path: /tmp/{{ inventory_hostname }}_*.html dest: /tmp/NMON-{{ inventory_hostname }}.zip format: zip when: option == "5" delegate_to: localhost -名称:'创建{date\u input}}NMON HTML文件的zip存档' 档案文件: 路径:/tmp/{{inventory\u hostname}}}.*.html dest:/tmp/NMON-{inventory\u hostname}}.zip 格式:zip 时间:选项==“5” 委托给:localhost