如何检查列表是否包含 Ansible Rundeck 中的项目

How to check whether the list have items in Ansible Rundeck

Objective:

代码:

- name: "Find the text files"
    find:
      paths: /directory/
      patterns: '*.txt'
    register: file_in_directory

  - name: Get the file name and its path
    set_fact:
      file_name_with_path: "{{ file_in_directory.files[0].path }}"
    when: "{{ file_in_directory.files[0].path }}" != ""

问题: 当条件失败时。

when: "{{ file_in_directory.files[0].path }}" != ""

有什么建议吗

我试过了,对我有用。

when: file_in_directory.matched > 0

或者您可以尝试:

when: file_in_directory.files | length > 0