2016-09-17 18 views
2

我想用下面的任務在一個劇本:如何在'with_first_found'中使用'skip:true'?

- include: "{{ prerequisites_file }}" 
    with_first_found: 
    - "prerequisites-{{ ansible_distribution }}.yml" 
    - "prerequisites-{{ ansible_os_family }}.yml" 
    loop_control: 
    loop_var: prerequisites_file 

我想它只是傳遞如果沒有找到相匹配的架構文件。

在運行時由於是,在這種情況下,它會產生一個錯誤:

TASK [ansible-playbook : include] ***************************************
fatal: [ansible-playbook]: FAILED! => {"failed": true, "msg": "No file was found when using with_first_found. Use the 'skip: true' option to allow this task to be skipped if no files are found"}

我知道我可以在末尾添加一個虛擬文件,但如果我照做,我怎麼應該在這裏添加skip: true選項?

這絕對不是include模塊的參數,它應該得到某種必然with_first_found條款...

回答

6

with_first_found有很多參數的變化。看看first_found.py - 文件開頭有一些例子。

回答你的問題:

- include: "{{ prerequisites_file }}" 
    with_first_found: 
    - files: 
     - "prerequisites-{{ ansible_distribution }}.yml" 
     - "prerequisites-{{ ansible_os_family }}.yml" 
     skip: true 
    loop_control: 
    loop_var: prerequisites_file