婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > ansible刪除目錄下所有內容的方法

ansible刪除目錄下所有內容的方法

熱門標簽:ec外呼系統怎么樣 天津外呼系統運營商 貴陽語音電銷機器人 貴港市機器人外呼系統團隊 蕪湖呼叫中心外呼系統哪家強 咸陽穩定外呼系統公司 漯河電銷外呼系統價格 征服者快捷酒店地圖標注 電銷機器人怎么錄音

使用ansible的同學都知道,ansible只支持新增刪除具體的某個文件夾或者文件,如下所示:

1. 創建目錄,刪除整個目錄

- 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

2.創建文件,刪除單個文件

- 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

對于某些場景,我們想清空log文件夾或者緩存文件夾,這個時候就僅僅需要刪除目錄下的所有內容而已。

3.刪除某個目錄下的所有文件,或者符合條件的文件名

#先使用shell模塊獲取該目錄下所有文件名,并且存儲到一個變量files_list
- name: list the files of dir some_directory
 shell: ls
 args:
  chdir: /appvol/some_directory
 register: files_list
 
#使用with_items屬性,將files_list變量以lines的形式輸出,再借助file模塊循環刪除每個文件
- name: Remove a directory if it does not exist
 file:
  path: /appvol/some_directory/{{ item }}
  state: absent
 with_items:
  - "{{ files_list.stdout_lines }}"

參考ansible官方文檔:

ansible file 模塊參考: refer to https://docs.ansible.com/ansible/latest/modules/file_module.html?highlight=file

ansible shell模塊參數:https://docs.ansible.com/ansible/latest/modules/shell_module.html?highlight=shell

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

標簽:西寧 東營 西藏 怒江 濰坊 攀枝花 淮北 香港

巨人網絡通訊聲明:本文標題《ansible刪除目錄下所有內容的方法》,本文關鍵詞  ansible,刪除,目,錄下,所有,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《ansible刪除目錄下所有內容的方法》相關的同類信息!
  • 本頁收集關于ansible刪除目錄下所有內容的方法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 门源| 巧家县| 文安县| 象州县| 上林县| 鹰潭市| 梅州市| 瓮安县| 阜新| 托里县| 襄汾县| 定西市| 商洛市| 长宁区| 伊通| 秦皇岛市| 故城县| 南和县| 栾川县| 通许县| 广汉市| 梁山县| 南江县| 新野县| 获嘉县| 阿尔山市| 六安市| 临沭县| 越西县| 延安市| 葵青区| 蒲江县| 巴林右旗| 会同县| 剑河县| 宁夏| 尉氏县| 星子县| 鄢陵县| 通榆县| 长泰县|