我在我的运算符中收集了ansible_date_time事实,但希望将其显示为"月日,时间",例如东部时间的"5 月 10 日晚上 10:36"在我的 statusDescriptor 字段中。我们如何使用 ansible 实现这一目标?
用户2700022非常接近,但是当ansible提供strftime
过滤器时,掏出到外部进程并不是"ansible-y"(此外,lookup("pipe"...
版本希望提供格式化字符以产生您要求的输出格式(
因此:
- debug:
msg: '{{ "%b %d %I:%M %p" | strftime }}'
# May 11 10:11 PM
您可以使用lookup
插件来实现此目的。
tasks:
- debug: msg="{{ lookup('pipe','date') }}"
由于pipe
返回给定命令的输出,因此您可以构建可用于date
命令的任何可能格式。有关日期支持的可能格式,请运行man date