目标:
代码:
- 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条件失败。
when: "{{ file_in_directory.files[0].path }}" != ""
请提出任何建议
答案 0 :(得分:0)
我尝试了这个,对我有用。
when: file_in_directory.matched > 0
答案 1 :(得分:0)
或者您可以尝试:
when: file_in_directory.files | length > 0