濮阳杆衣贸易有限公司

主頁 > 知識庫 > ansible刪除目錄下所有內(nèi)容的方法

ansible刪除目錄下所有內(nèi)容的方法

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

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

1. 創(chuàng)建目錄,刪除整個目錄

- 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.創(chuàng)建文件,刪除單個文件

- 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文件夾或者緩存文件夾,這個時候就僅僅需要刪除目錄下的所有內(nèi)容而已。

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模塊循環(huán)刪除每個文件
- 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模塊參數(shù):https://docs.ansible.com/ansible/latest/modules/shell_module.html?highlight=shell

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

標(biāo)簽:西寧 東營 西藏 怒江 濰坊 攀枝花 淮北 香港

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ansible刪除目錄下所有內(nèi)容的方法》,本文關(guān)鍵詞  ansible,刪除,目,錄下,所有,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ansible刪除目錄下所有內(nèi)容的方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于ansible刪除目錄下所有內(nèi)容的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    开原市| 高台县| 阳东县| 临漳县| 常山县| 和林格尔县| 五河县| 高阳县| 民乐县| 台中县| 丰顺县| 桓台县| 玉田县| 湖北省| 武安市| 临漳县| 富民县| 江源县| 泌阳县| 繁峙县| 凌源市| 赫章县| 甘洛县| 东辽县| 博兴县| 咸丰县| 深圳市| 钟祥市| 庐江县| 怀来县| 新竹县| 屏东市| 泸州市| 南丹县| 临朐县| 双城市| 桐梓县| 上思县| 永川市| 车险| 资溪县|