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
debug:
msg: "{{ ansible_date_time.date }}"
Something like this should be returned.
TASK [current date]
ok: [server1.example.com] => {
"msg": "2020-12-11"
}
Or the time.
- name: current time
debug:
msg: "{{ ansible_date_time.time }}"
Something like this should be returned.
TASK [current time]
ok: [server1.example.com] => {
"msg": "01:54:08"
}
Usually, you are going to want to format the output, like this.
vars:
date: "{{ ansible_date_time.year }}-{{ ansible_date_time.month }}-{{ ansible_date_time.day }}"
time: "{{ ansible_date_time.hour }}:{{ ansible_date_time.minute }}:{{ ansible_date_time.second }}"