# Timestamp without gathering facts

**URL:** <https://forum.ansible.com/t/timestamp-without-gathering-facts/22073>\
**Category:** Ansible Project\
**Created:** [July 21, 2016, 4:07am UTC](https://forum.ansible.com/t/timestamp-without-gathering-facts/22073 "2016-07-21T04:07:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [July 21, 2016, 4:07am UTC](https://forum.ansible.com/t/timestamp-without-gathering-facts/22073/1 "2016-07-21T04:07:43Z")

</div>

I want to come up with a timestamp for the current time; it doesn't have  
to be perfectly accurate, this is just to uniquely name something, but if  
I run it twice in a row I want to be pretty sure that the second time will  
be later than the previous time. Something like this:

- name: Do something with a timestamp in it  
&nbsp;&nbsp;hosts: some\_hosts  
&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;something\_name: "{{ inventory\_hostname }}-{{ ansible\_date\_time['epoch'] }}"

And then I'll use something\_name in a task later on.

I can use ansible\_date\_time, but that seems to be a fact gathered from the  
target host, which raises the possibility that I'll get a timestamp that's  
not very accurate if the target host's clock is off, and in particular if  
I do this twice in a row, once for one host and once for another, the  
second one might not be later than the first (and the two might not be  
unique if the clocks happen to be off by just the right amount).

Also, I'd just as soon not have to gather facts at all, since I don't  
happen to need any for the tasks I have in mind. Among other things, I  
could then do my thing even if the target host wasn't up and running at  
the moment.

Also, if I run the play such that some\_hosts includes multiple hosts, I'd  
like them all to have the same timestamp.

[https://groups.google.com/d/msg/ansible-project/lPmj6Y5XxUg/TC9bu7Pbu8QJ](https://groups.google.com/d/msg/ansible-project/lPmj6Y5XxUg/TC9bu7Pbu8QJ)  
suggests that something like

&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;something\_name: "{{ inventory\_hostname }}-{{ lookup('pipe', 'date +%s') }}"

should work -- and indeed it seems to -- but it feels hinky to have to  
open a pipe to an external command just to find the current timestamp,  
which Ansible on the control host must surely know.

Is the current timestamp, according to the control host, available in a  
variable somewhere? I didn't find it by searching for "date" or "time" on  
[http://docs.ansible.com/ansible/playbooks\_variables.html](http://docs.ansible.com/ansible/playbooks_variables.html).

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

(apologies for the automatic corporate disclaimer that follows)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 8, 2017, 9:49pm UTC](https://forum.ansible.com/t/timestamp-without-gathering-facts/22073/2 "2017-03-08T21:49:21Z")

</div>

You can use a lookup to query the 'controller's date' lookup('pipe',  
'date ....')
