ansible file 模塊參考: refer to https://docs.ansible.com/ansible/latest/modules/file_module.html?highlight=filehtml
ansible shell模塊參數:https://docs.ansible.com/ansible/latest/modules/shell_module.html?highlight=shellshell
ansible 刪除多個文件和目錄:http://www.javashuo.com/article/p-efszcrld-cu.htmlapp
- name: Create a directory if it does not exist file: path: /appvol/some_directory state: directory mode: '0755' - name: Remove a directory if it exist file: path: /appvol/some_directory state: absent
- name: Create a file if it does not exist file: path: /appvol/some_directory/hello.txt state: touch mode: '0755' - name: Remove a file if it exist file: path: /appvol/some_directory/hello.txt state: absent
- name: list the files of dir some_directory shell: ls args: chdir: /appvol/some_directory register: files_list - name: Remove a directory if it does not exist file: path: /appvol/some_directory/{{ item }} state: absent with_items: - "{{ files_list.stdout_lines }}"