Last active
May 12, 2025 00:40
-
-
Save TyeolRik/29a589868eae002cf3a691ba505c4bd5 to your computer and use it in GitHub Desktop.
Calculate (Print) Time cost in millisecond on Ansible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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