Ansible - 将日期增加“X"天/分钟 [英] Ansible - Increment date by 'X' days/minutes

查看:37
本文介绍了Ansible - 将日期增加“X"天/分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

变量 ansible_date_time.date 给出当前日期和时间戳,但是我希望将此日期增加 'X' 分钟/天.是否有任何内置方法或逻辑来执行此操作?

The variable ansible_date_time.date gives the current date and time stamp, however I wish to increment this date by 'X' minutes/days. Is there any built in method or logic to do this?

- 运算符似乎适用于日期操作数,但似乎没有任何直接的方法来增加日期.

The - operator seems to work with date operands, however there doesn't seem to be any straightforward way to increment a date.

我想在 yml 脚本本身中完成此操作,而不是使用 是否可以在 Ansible Playbook 中操作日期

I want to accomplish this in a yml script itself and not by using additional Python scripting as described in Is it possible to manipulate the date in an Ansible Playbook

推荐答案

可以使用命令模块来增加当前日期,如下面的代码片段所示.这按预期对我有用.

The command module can be used as shown in the following snippet to increment the current date. This worked for me as expected.

- command: "date +'%d-%m-%Y' -d '+3 days'"
  register: result

- debug: msg="{{result.stdout}}"

这将以 dd-mm-yyyy 格式返回日期.例如,如果今天的日期是03-07-2017",它会将日期增加 3 天(如上面示例代码段中显示的命令所述)并返回06-07-2017".

This will return the date in dd-mm-yyyy format. For example, if today's date is "03-07-2017", it will increment the date by 3 days (as mentioned in the command shown in above example snippet) and would return "06-07-2017".

这篇关于Ansible - 将日期增加“X"天/分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆