如何检查列表中是否有Ansible Rundeck中的项
目标:如何检查列表中是否有Ansible Rundeck中的项,ansible,rundeck,Ansible,Rundeck,目标: - 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 }}"
- 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 }}" != ""
- 在具有模式的目录中查找文件并将其放入列表中
- 然后检查列表是否为空。如果不是空的,则提取文件名
- 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
使用json_查询。