python - Ansible:条件寄存器检查
问题描述
我正在创建一个剧本来执行一个动作,但有一个条件:只有在日期早于 x 天时才执行我的命令
这是我尝试使用的
with_items: "{{ (my_register | sort(attribute='ctime'))[30:] | list }}"
- name: some action
shell: some command | grep command
register: my_register
ignore_errors: True
- name: conditional action
shell: command
become: yes
when: my_register
with_items: "{{ (my_register | sort(attribute='ctime'))[x days:] | list }}"
我希望检查“my_register”中的信息是否超过 x 天。
解决方案
我已经用测试文件进行了测试。请检查这是否对您的方案有用。在什么情况下你可以给出如下
- name: Test
stat:
path: /tmp/test.txt
register: output
- name: conditional action
shell: command
become: yes
when: (ansible_date_time.epoch|int - output.stat.ctime|int) < 2592000
注意:2592000 是以秒为单位的 30 天
推荐阅读
- ios - 有没有办法在应用程序在 ios 中处于后台时查找用户是否正在打字?
- python - 在熊猫数据框中打开文件内容时如何维护二进制数值
- python - 查找序列并删除以前的条目
- flutter - 单击按钮时在同一屏幕上显示 TextField 值
- ios - 如何在颤振项目中使用 Firebase 实现电话身份验证?
- xamarin - 如果应用程序被杀死,UIBGTaskScheduler 会工作吗?
- python - 有没有办法捕获用户未通过身份验证的异常?
- node.js - 错误:当我想在 ejs 文件中显示时,它们发送到客户端后无法设置标题
- csv - tshark 不会将 TCP 碎片组装成大数据包
- c - AIX - XercesC 运行时错误:未找到符号的运行时定义