0
在Ansible 2.2中,我想遍历从S3中读取的大量文件。ansible包含数组切片
这里是我的role/tasks/main.yml
- name: Simulate variable read from S3 set_fact: list_of_files_to_import: [ "a.tar.gz", "b.tar.gz", "c.tar.gz", "d.tar.gz", "e.tar.gz", "f.tar.gz", "g.tar.gz", "h.tar.gz", ... "zz.tar.gz" ] - name: Process each file from S3 include: submodule.yml with_items: list_of_files_to_import
这里是role/tasks/submodule.yml
--- - name: Restore TABLE {{ item }} debug: var={{ item }}
这崩溃,因为有太多的文件。
我发现,我可以切片的阵列,并在同一时间发送部分:
- name: Process each file from S3 include: submodule.yml with_items: "{{ list_of_files_to_import[0:5] }}" - name: Process each file from S3 include: submodule.yml with_items: "{{ list_of_files_to_import[5:10] }}" - name: Process each file from S3 include: submodule.yml with_items: "{{ list_of_files_to_import[10:15] }}" - name: Process each file from S3 include: submodule.yml with_items: "{{ list_of_files_to_import[15:20] }}"
而是硬编码这些小块,我想尝试像
- name: Process each file from S3 include: submodule.yml with_items: "{{ list_of_files_to_import[{{start}}:{{end}}] }}"
但我们cannot get variable-defined variable names
如何处理Ansible 2.2中的大量项目?
列表有多大?崩溃的原因是什么?太多包括? –
它是300个文件的顺序。我看到的唯一原因是“内存不足”。但是,是的,它似乎不能处理这么多包括。 –
我不确定您的详情,但它看起来像问题[#16391](https://github.com/ansible/ansible/issues/16391)。如果是这样的话,这个问题应该在下一个Ansible版本中解决。 – nelsonda