2016-01-14 41 views
6

我使用ansible 1.9.4,我想從本地目錄中獲取文件列表。 在2.0版本中,有查找模塊,但此版本是測試版。Ansible:從本地目錄中獲取文件列表

如何在< 2.0中做到這一點?

謝謝

+0

其實Ansible 2不再是beta版,它已經在兩天前發佈了。 http://www.ansible.com/blog/ansible-2.0-launch – udondan

+0

太好了。我會嘗試這個 – Kiva

+0

它可能在1.9.4。你究竟想要做什麼? – helloV

回答

8

前段時間我正在建立一個自動化,需要類似的東西。你可以檢查我的問題here

在安全2.0之前,如果不使用commandshell,則無法執行此操作。

如果你真的不能升級到2.0 ansible,使用command模塊:

vars: 
    directory: /path/to/dir 

tasks: 

    - command: "ls {{directory}}" 
    register: dir_out 

    - debug: var={{item}} 
    with_items: dir_out.stdout_lines 
+0

謝謝。我想過這個模塊,但我覺得這很醜陋。但如果這是唯一的解決方案,那就走吧。 – Kiva

5

這是列出了所有的文件與.j2擴展目錄中的模板,並將它們傳遞給一個模塊的例子。

template: src="{{ item }}" dest="generated/{{ inventory_hostname }}/{{ item | basename | replace('.j2', '')}}" 
    delegate_to: 127.0.0.1 
    with_fileglob: templates/*.j2 
相關問題