Ansible playbook中哈希变量中所有成员的测试值

Ansible playbook中哈希变量中所有成员的测试值,ansible,jinja2,Ansible,Jinja2,仅当预定义文件列表中的一个或多个文件丢失时,我才需要运行任务。我尝试了以下方法(以及一些变体): “when:”子句中使用的正确语法是什么?还是这条路完全错了?谢谢您的费心! - hosts: localhost gather_facts: false vars: file_vars: - {name: file1} - {name: file2} tasks: - name: Checking existing file name

仅当预定义文件列表中的一个或多个文件丢失时,我才需要运行任务。我尝试了以下方法(以及一些变体):


“when:”子句中使用的正确语法是什么?还是这条路完全错了?

谢谢您的费心!
- hosts: localhost
  gather_facts: false
  vars:
    file_vars:
      - {name: file1}
      - {name: file2}
  tasks:
    - name: Checking existing file name
      stat:
        path: ./{{ item.name }}
      with_items: "{{ file_vars }}"
      register: check_file_name

    - debug:
        msg: 'file name {{item.item.name}} not exists'
      with_items: "{{ check_file_name.results }}"
      when: item.stat.exists == False

    - name: Create file
      file:
        path: "./{{item.item.name}}"
        state: touch
      with_items: "{{ check_file_name.results }}"
      when: item.stat.exists == False
- hosts: localhost
  gather_facts: false
  vars:
    file_vars:
      - {name: file1}
      - {name: file2}
  tasks:
    - name: Checking existing file name
      stat:
        path: ./{{ item.name }}
      with_items: "{{ file_vars }}"
      register: check_file_name

    - debug:
        msg: 'file name {{item.item.name}} not exists'
      with_items: "{{ check_file_name.results }}"
      when: item.stat.exists == False

    - name: Create file
      file:
        path: "./{{item.item.name}}"
        state: touch
      with_items: "{{ check_file_name.results }}"
      when: item.stat.exists == False