【发布时间】:2020-11-26 08:29:14
【问题描述】:
我只想在多个文件存在时执行任务。如果只存在单个文件,我需要忽略此任务。我怎样才能做到这一点。 我无法通过以下剧本实现
---
- name: Standardize
hosts: test
gather_facts: false
vars:
file_vars:
- {id: 1, name: /etc/h_cm}
- {id: 2, name: /etc/H_CM}
tasks:
- block:
- name: Check if both exists
stat:
path: "{{ item.name }}"
with_items: "{{ file_vars }}"
register: cm_result
- name: Move both files
shell: mv "{{ item.item }}" /tmp/merged
with_items: "{{ cm_result.results }}"
when: item.stat.exists
【问题讨论】:
标签: linux file ansible ansible-facts