today I tried to calculate the elapsed time of a module execution in a playbook.
Here an example code:
- name: Get start time
ansible.builtin.set_fact:
startTime: "{{ now() }}"
- name: The module to be measured
...
- name: Get end time
ansible.builtin.set_fact:
endTime: "{{ now() }}"
- name: Try to calculate elapsed time, but it does not work
ansible.builtin.debug:
msg: "{{ (endTime - startTime) }}"
Unfortunately I have not found a way to calculate the elapsed time.
Now I have two questions:
What would be the correct approach for calculating with times?
Is there another or better approach to measure the elapsed time of module executions in a playbook?
what @Lyle_McKarns is the best approach, yours could work, but you are not giving any indication no ‘how it does not work’ so it is very hard to give you a solution.
Normally you want to give the exact error and if possible extended verbose and/or debug information when asking for help.