Ansible-将日期增加"X"天/分钟 [英] Ansible - Increment date by 'X' days/minutes
问题描述
变量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.
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屋!