2016-12-07 75 views
0

我想在Ansible的這個輸出中定位路徑變量。Ansible - 如何定位項目

ok: [myMachine1] => { 
    "foundFiles": { 
     ... 
     "results": [ 
      { 
       ... 
       "files": [ 
        { 
         ... 
         "path": "/my/first/path", 
         ... 
        } 
       ], 

      }, 
      { 
       ... 
       "files": [ 
        { 
         ... 
         "path": "/my/second/path", 
         ... 
        } 

      } 
     ] 
    } 
} 

我該如何告訴Ansible目標'路徑'變量。 我想有:

- debug: 
    msg: "{{ item.files.path }}" 
    with_items: 
    - foundFiles.results 

但只得到"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'unicode object' has no attribute 'key'

感謝大師的。

回答

1

第一:裸變量不支持,因爲Ansible 2.2
二:files是你們的榜樣名單

- debug: msg="{{ item.files[0].path }}" 
    with_items: "{{ foundFiles.results }}" 

如果你有下files列表多個條目,你應該考慮到map它。