我想使用 ansible 删除旧文件。我有一个数据日志文件夹,在这个文件夹中我有多个目录:
/data/log/folder1/
/data/log/folder2/
....
我尝试使用这个 ansible 剧本:
---
- hosts: all
tasks:
- name: find all files that are older than 10 days
find:
paths: /data/log/*/
age: 10d
recursive: yes
register: filesOlderThan10
- name: remove older than 10
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ (filesOlderThan10.files }}"
当我启动 playbook 时,没有任何内容被删除,我不确定我是否可以使用这种语法 /data/log/*/
因此,我正在寻找改进此代码的建议
最佳答案
到目前为止,我在剧本中发现了三四个错误
下面的代码应该可以工作
---
- hosts: all
tasks:
- name: find all files that are older than 10 days
find:
paths: /data/log
age: 10d
recurse: yes
register: filesOlderThan10
- name: remove older than 10
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ filesOlderThan10.files }}"
https://stackoverflow.com/questions/65178367/
相关文章:
python - 如何在输出文件中返回输入文件的第 k 个元素?
python - 从 Pandas 数据框中同一字段的所有其他行中减去一行字段中的值
reactjs - 类型 'onClick' 上不存在属性 '{ children?: ReactN
list - 如何将列表合并到 Elixir 中的元组列表中?
linux-kernel - linux cdc_ecm 驱动程序与 rndis 驱动程序
linux - 如何使用 xargs 将 ls 通过管道传输到 cat 中,以便列出文件名?
google-apps-script - 无法读取 null 的属性 'getSheetByName