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
hosts: some_hosts
vars:
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
suggests that something like
vars:
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.
-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.