Member-only story

Mastering Time in Ansible: An Introduction to the now() Function

Effortlessly Schedule Tasks and Manage Timings with Ansible’s now() Function

Luca Berton
5 min readMar 7, 2024

Introduction

In the realm of IT automation, timing and scheduling tasks are crucial for managing systems efficiently. Ansible, a powerful automation tool, facilitates this through various functions, including the now() function, which is an essential tool for fetching the current time within playbooks. This function, introduced in Ansible 2.8, utilizes the Jinja2 templating engine to retrieve a Python datetime object or a string representation of the current time, providing flexibility and precision in timing operations. This article will explore the now() function in detail, highlighting its usage and practical applications within Ansible automation tasks.

Overview of the now() Function

The now() function is a Jinja2 extension that Ansible playbooks can use to obtain the current time. This function is incredibly versatile, supporting arguments to adjust the time zone to UTC and to format the datetime string according to specific needs.

Arguments Supported by now()

  • utc: By setting this argument to True, you can obtain the current time in…

--

--

Luca Berton
Luca Berton

Written by Luca Berton

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday

No responses yet