Date in a Jinja template

24 views
Skip to first unread message

lift...@gmail.com

unread,
Dec 8, 2020, 9:19:44 AM12/8/20
to Ansible Project
I generate a report using a Jinja template file from one of my playbooks and mail that file to several users.  In it, I am putting the current date and time as follows:

Date generated: {{ now(false, '%m/%d/%Y %I:%M:%S') }}
---
{% for i in play_hosts | sort %}
Host: {{ i }}
      Rebooted: {{ hostvars[i]['rebooted']['rebooted'] }}
      Total reboot time: {{ hostvars[i]['rebooted']['elapsed'] }} seconds
---
{% endfor %}

When I get the email, the date is correct but the time is 7 hours off.  For example, the report was generated and mailed at 10:40:00am yesterday, but the time listed via the Jinja template above was 03:40:00.

Any ideas on how to get the time be in the current timezone?

Thanks,
Harry

Dick Visser

unread,
Dec 8, 2020, 9:49:46 AM12/8/20
to ansible...@googlegroups.com
I think now() is naive, i.e. it does not know about time zones.
If you need time zones, then I'd give 'ansible_date_time' a try.
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8d957e26-0a8b-40bd-9dd4-f7b4f3297a29n%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

harry devine

unread,
Dec 8, 2020, 11:09:26 AM12/8/20
to ansible...@googlegroups.com
Thank you!  That worked very well. 

Harry 

Reply all
Reply to author
Forward
0 new messages