- name: Display current date and time ansible.builtin.debug: msg: "Current date and time is {{ ansible_date_time.date }}"
获取到的日期格式是YYYY-MM-DD, 如果想改成其他格式,可以使用正则获取年月日
1 2 3
- name: Format current date ansible.builtin.debug: msg: "Formatted date: {{ ansible_date_time.date | regex_replace('^(\\d{4})-(\\d{2})-(\\d{2})$', '\\3/\\2/\\1') }}"
\1 - 年
\2 - 月
\3 - 日
获取当前时间
1 2 3
- name: Display current date and time ansible.builtin.debug: msg: "Current date and time is {{ ansible_date_time.time }}"