使用找到的第一个\u执行Ansible查找并跳过

使用找到的第一个\u执行Ansible查找并跳过,ansible,Ansible,我想使用first\u found及其skip选项在Ansible中执行查找。为此,我创作了以下剧本: - name: Include group playbooks include: "{{lookup('first_found', dict=(files=[item + '.yml', 'empty.yml'], skip=true))}}" with_items: "{{group_names}}" 但是,我收到此错误: ERROR! Unexpected Exception:

我想使用
first\u found
及其
skip
选项在Ansible中执行查找。为此,我创作了以下剧本:

- name: Include group playbooks
  include: "{{lookup('first_found', dict=(files=[item + '.yml', 'empty.yml'], skip=true))}}"
  with_items: "{{group_names}}"
但是,我收到此错误:

ERROR! Unexpected Exception: '_raw_params'

如何通过
skip
选项

首先,我怀疑您的
dict=
参数传递。请参阅我的答案以了解正确的呼叫

关于您的错误:
first\u found
lookup with
skip
选项在未找到任何内容时返回空列表,但
include
语句要求文件名作为自由格式参数

您可以这样解决它:

- name: Include group playbooks
  include: "{{ filename }}"
  when: filename is string
  vars:
    filename: "{{ lookup('first_found', dict(files=[item + '.yml', 'empty.yml'], skip=true)) }}"
  with_items: "{{group_names}}"

啊。。。我懂了!我误解了错误实际发生的地方。使用上面的代码,它现在可以工作了。谢谢你的帮助!