BacklogZero®

Ansible in a Minute · Ansible Core ·

Use now to get the current time in a template

Short answer

Use now() when you need the current time, not the time facts were gathered.

Subscribe for updates

Get an email whenever we publish new guides and blog posts. Unsubscribe anytime.

By subscribing you agree we may email you about Ansible in a Minute and related Level Up Labs updates. We store your address in the same lead sheet as our contact form.

Request

print current UTC time with now() fmt ISO

Example

A quick heads-up: Every environment is different. Review and test this example before you run it on systems you care about.

YAML
---
- name: Print the current UTC time with now
  hosts: all
  gather_facts: false
  tasks:
    - name: Print current UTC time
      ansible.builtin.debug:
        msg: "{{ now(utc=true, fmt='%Y-%m-%dT%H:%M:%SZ') }}"

How it works

now() evaluates when the template renders. ansible_date_time is a gathered fact and stays fixed for the play. Use now() for stamps, names, and messages that must reflect the current clock.

When to use it

  • Timestamping a report or artifact name
  • Recording the time a task actually ran

Requirements

  • Ansible: >=2.14

Validation

  • Syntax validated
  • Not execution-tested
  • Last verified 2026-09-15

Notes

now(utc=true) uses UTC. fmt is a Python strftime string. You do not need gather_facts to use now().

Reference

Built for every Ansible use case in every organization

BacklogZero can generate this kind of automation in your environment, just like it did here.

Get BacklogZero today

Related guides

Back to Ansible in a Minute

Use now to get the current time in a template · Level Up Labs