2017-12-27 18 views
0

フォルダ内のすべてのファイルとディレクトリを削除しない:Ansible:私はフォルダ自体を削除せずに、私のプロジェクトのfiolderのすべてのコンテンツを削除し、タスクを実行しようとしているフォルダ自体

私のフォルダ :appFolder ----含ま----> FILE1、FILE2 ... fileN、directory1の... directoryN

iは、LSfileGlobを使用しようとしましたましたが、それは動作しませんでした正しく。

シェルモジュールとも
- name: delete old version files 
    file: 
    path: "{{ paths }}" 
    state: absent 
    with_filesglob: 
    - "{{paths}}deletes/*" 

(よくない、それは特殊文字の名前を持つファイルを削除しなかったため)

- shell: ls -1 /some/dir 
    register: contents 

- file: path=/some/dir/{{ item }} state=absent 
    with_items: {{ contents.stdout_lines }} 

よりよい解決策?

答えて

1

#18910が固定されるまで(dirsの場合はstate=empty)、回避策があります。

ここではそのうちの一つだ:

- name: Clean build folder 
    shell: cd /project/build && find -mindepth 1 -maxdepth 1 -print0 | xargs -0 rm -rf -- 
関連する問題