In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to use ansible to delete all the content in the directory, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
1. Create a directory and delete the entire directory
-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
two。 Create files and delete individual files
-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
For some scenarios, if we want to empty the log folder or cache folder, we just need to delete everything in the directory.
3. Delete all files in a directory, or eligible file names
# first use the shell module to get all the file names in this directory, and store them in a variable files_list- name: list the files of dir some_directory shell: ls args: chdir: / appvol/some_directory register: files_list # use the with_items attribute to output the files_list variable as lines Then delete each file in a loop with the help of the file module-name: Remove a directory if it does not exist file: path: / appvol/some_directory/ {{item}} state: absent with_items:-"{{files_list.stdout_lines}}" the above is how to delete everything in the directory using ansible. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.