I want to create a file name by formatting datetime.now()
. It is simple enough in Python, but the datetime
module needs to be imported. How can I import it for use in a Jinja2 template?
For example, in this Ansible task:
- name: myTask
shell: echo "123" > /tmp/{{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}}.zaz
Ansible already knows about the date/time.
See this page for a list of default systems facts.