Skip to content

Instantly share code, notes, and snippets.

@TyeolRik
Last active May 12, 2025 00:40
Show Gist options
  • Save TyeolRik/29a589868eae002cf3a691ba505c4bd5 to your computer and use it in GitHub Desktop.
Save TyeolRik/29a589868eae002cf3a691ba505c4bd5 to your computer and use it in GitHub Desktop.
Calculate (Print) Time cost in millisecond on Ansible
---
- name: Time check
hosts: all
gather_facts: true
tasks:
- name: Set current time
ansible.builtin.set_fact:
start_time: "{{ now().timestamp() | float }}"
- name: Sleep 3 second
ansible.builtin.wait_for:
timeout: 3
- name: Now time
ansible.builtin.debug:
msg: "It costs {{ (now().timestamp() | float) - (start_time | float) }} seconds."
# "msg": "It costs 3.3215749263763428 seconds."
- name: Now time with round 3 decimal point
ansible.builtin.debug:
msg: "It costs {{ ((now().timestamp() | float) - (start_time | float)) | round(3) }} seconds."
# "msg": "It costs 3.322 seconds."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment