-1
我正在使用模块stat来检查某些文件是否存在于远程服务器中,并将其结果注册到变量中。即我正在查找的配置文件:conf_dev.conf,conf_pred.conf,conf_pro.conf。Ansible - 如何循环注册
稍后,我使用复制模块仅使用基于存储在 variable.results {{(ITEM)index}}。stat.exists中的属性使用条件来丢失文件。 如果文件存在,则返回TRUE,否则返回FALSE。
对于正常运行由于寄存器变量是一个数组有一个索引存储每个文件的结果我问,所以我不知道如何转换索引中的项目(0,1,2,3 )
有谁知道如何获得项目的索引?我已经试过这(看最后一行):
- name: Checking if common configuration files exists
stat:
path: "{{HOME_COMUN_CONFIG}}/{{item}}"
with_items: "{{LIST_COMMON_CONFIGURATION_ARTIFACTS}}"
register: store_results
- name: debug existe_app_comun
debug:
var: store_results
- name: Deploying missing files
copy:
src: "{{DIRTEMP_COMUN_CONFIG}}/{{item}}"
dest: "{{HOME_COMUN_CONFIG}}/{{item}}"
with_items: "{{LIST_COMMON_CONFIGURATION_ARTIFACTS}}"
when: existe_app_comun.results.{{index(item)}}.stat.exists is defined