Ansible - ansible_date_time fact

ansible_date_time is a magic variable that returns date/time on the managed node (e.g. the target system). Or, the lookup plugin and date can be used. Or, the strftime (string format time) filter can be used.

In this example, the debug module is used output the current date.

- name: current date
    msg: "{{ }}"


Something like this should be returned.

TASK [current date]
ok: [] => {
    "msg": "2020-12-11"


Or the time.

- name: current time
    msg: "{{ ansible_date_time.time }}"


Something like this should be returned.

TASK [current time]
ok: [] => {
    "msg": "01:54:08"


Usually, you are going to want to format the output, like this.

  date: "{{ ansible_date_time.year }}-{{ ansible_date_time.month }}-{{ }}"
  time: "{{ ansible_date_time.hour }}:{{ ansible_date_time.minute }}:{{ ansible_date_time.second }}"


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 6aee6 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |