I'm trying to set up Cloudformation time as fact as below
- name: Set Cloud Formation launch time as fact
set_fact:
elasped_time: "{{ (ansible_date_time.iso8601[:19] | to_datetime(date_fmt) - ansible_facts['cloudformation'][stack_name]['stack_description']['creation_time'][:19] | to_datetime(date_fmt)).total_seconds() / 3600 | int }}"
connection: local
But I'm getting the below error:-
*{"msg": "The task includes an option with an undefined variable. The error was: Unable to look up a name or access an attribute in template string ({{ (ansible_date_time.iso8601[:19] | to_datetime(date_fmt) - ansible_facts['cloudformation'][stack_name]['stack_description']['creation_time'][:19] | to_datetime(date_fmt)).total_seconds() / 3600 | int }}).\nMake sure your variable name does not contain invalid characters like '-': strptime() argument 1 must be str, not AnsibleUndefined\n\nThe offending line appears to be:\n\n\n- name: Set Cloud Formation launch time as fact\n ^ here\n"}*
Can someone suggest how to fix this?