Hello. My task is calculate a playbook runtime. I get this error: “the field ‘args’ has an invalid value ({‘end_time’: ‘{{ ansible_date_time.iso8601[:19] }}’, ‘runtime’: ‘{{ ((ansible_date_time.iso8601[:19] | to_datetime) - (start_time | to_datetime)).seconds }}’}), and could not be converted to an dict.The error was: time data ‘2026-05-07T12:14:03’ does not match format ‘%Y-%m-%d %H:%M:%S’”
Here is the playbook with the actual tasks removed as they work fine (but may be the identation is the issue because there are a couple of conditional blocks by the time the comparison is made:
---
- name: Get all task metadata for the DCR project
hosts: localhost
connection: local
gather_facts: true
vars_files:
- vars/main.yml
pre_tasks:
- name: Set start time
set_fact:
start_time: "{{ ansible_date_time.iso8601[:19] }}"
tasks:
- name: Set fact for Ansible date_time | dcr_jira {{ ansible_date_time.iso8601 }}
delegate_to: localhost
run_once: true
set_fact:
currentdate: "{{ ansible_date_time.date }}"
tags: linux
Omitting some tasks, then:
- name: Force update of current timestamp
setup:
filter: 'ansible_date_time'
- name: Calculate runtime
set_fact:
end_time: "{{ ansible_date_time.iso8601[:19] }}"
runtime: "{{ ((ansible_date_time.iso8601[:19] | to_datetime) - (start_time | to_datetime)).seconds }}"
The output:
TASK [Archive the scratchpad directory into a zip file, move to /dcr_archived | dcr_jira 2026-05-07T12:13:55Z] *****************************************************************************************************************************
changed: [localhost]
TASK [Attach the refresh worklog | dcr_jira 2026-05-07T12:13:55Z] **************************************************************************************************************************************************************************
changed: [localhost]
TASK [Force update of current timestamp] ***************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [Calculate runtime] *******************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {}
MSG:
the field 'args' has an invalid value ({'end_time': '{{ ansible_date_time.iso8601[:19] }}', 'runtime': '{{ ((ansible_date_time.iso8601[:19] | to_datetime) - (start_time | to_datetime)).seconds }}'}), and could not be converted to an dict.The error was: time data '2026-05-07T12:14:03' does not match format '%Y-%m-%d %H:%M:%S'
The error appears to be in '/etc/ansible/dcr_jira.yml': line 388, column 15, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Calculate runtime
^ here
PLAY RECAP *********************************************************************************************************************************************************************************************************************************
localhost : ok=30 changed=6 unreachable=0 failed=1 skipped=17 rescued=0 ignored=0
[misoracle@ehsmg-mis-dba1 ansible]$
Why does the “runtime: “{{ ((ansible_date_time.iso8601[:19] | to_datetime) - (start_time | to_datetime)).seconds }}”” calculation fail? Both start and end formatted the same!
Thank you.
Nestor Kandinsky-Clerambeau.
