How do I get timestamps from every task that runs? Ideally I’d like a timestamp to show in the line with all the * showing the task name, but getting it on the following line would work.
I haven’t found a way to do it (and see this ask for the exact same thing in 2014: Including timestamps in PLAY [host] *** messages) and so what I am doing is inserting tasks between all of mine that are just:
- name: TimeStamp # noqa: no-changed-when
delegate_to: localhost
ansible.builtin.shell:
echo "TimeStamp:`date +'%Y%m%d-%H%M%S'`"
This a horrible way to do it, but I haven’t found any other options. I want to know when each task starts, so that I have some indication how long the previous one took.
Some example output that I currently have looks like this:
TASK [TimeStamp] *******************************************************************************************************************
changed: [localhost] => {"changed": true, "cmd": "echo \"TimeStamp:`date +'%Y%m%d-%H%M%S'`\"", "delta": "0:00:00.007684", "end": "2024-12-30 18:05:39.135224", "msg": "", "rc": 0, "start": "2024-12-30 18:05:39.127540", "stderr": "", "stderr_lines": [], "stdout": "TimeStamp:20241230-180539", "stdout_lines": ["TimeStamp:20241230-180539"]}
TASK [Create subnet] ***************************************************************************************************************
ok: [localhost] => {"changed": false, "state": {"address_prefix": "10.100.40.0/24", "address_prefixes": null, "id": "/subscriptions/<redacted>/resourceGroups/BuildPool0/providers/Microsoft.Network/virtualNetworks/BuildPool0/subnets/BuildPool0", "name": "BuildPool0", "nat_gateway": null, "network_security_group": {"id": "/subscriptions/<redacted>/resourceGroups/BuildPool0/providers/Microsoft.Network/networkSecurityGroups/BuildPool0", "name": "BuildPool0", "resource_group": "BuildPool0"}, "private_endpoint_network_policies": "Enabled", "private_link_service_network_policies": "Enabled", "provisioning_state": "Succeeded", "route_table": {}}}
TASK [TimeStamp] *******************************************************************************************************************
changed: [localhost] => {"changed": true, "cmd": "echo \"TimeStamp:`date +'%Y%m%d-%H%M%S'`\"", "delta": "0:00:00.007216", "end": "2024-12-30 18:05:41.422159", "msg": "", "rc": 0, "start": "2024-12-30 18:05:41.414943", "stderr": "", "stderr_lines": [], "stdout": "TimeStamp:20241230-180541", "stdout_lines": ["TimeStamp:20241230-180541"]}
TASK [Create VMSS] *****************************************************************************************************************
I’d like to the timestamp in the line showing the task name…like this:
TASK [Create subnet] [2024-12-30 18:05:39.127540] ******************************************
ok: [localhost] => {"changed": false, "state": {"address_prefix": "10.100.40.0/24", "address_prefixes": null, "id": "/subscriptions/<redacted>/resourceGroups/BuildPool0/providers/Microsoft.Network/virtualNetworks/BuildPool0/subnets/BuildPool0", "name": "BuildPool0", "nat_gateway": null, "network_security_group": {"id": "/subscriptions/<redacted>/resourceGroups/BuildPool0/providers/Microsoft.Network/networkSecurityGroups/BuildPool0", "name": "BuildPool0", "resource_group": "BuildPool0"}, "private_endpoint_network_policies": "Enabled", "private_link_service_network_policies": "Enabled", "provisioning_state": "Succeeded", "route_table": {}}}
TASK [Create VMSS] [2024-12-30 18:05:41.414943] ******************************************
Since the output shows start and end times, it is available when the task is shell…just put the start time in the task header line please. And, since I’m asking for something that doesn’t seem to exist, I’d like the ability to format the timestamp output as well, to fit my standards.
Any suggestions?