I would like to have a timestamp variable, which is the same across across all hosts. (I include this in the name of directories: it must be the same on all hosts)
My initial idea was to add a declaration into group_vars/all.yml, since that has a relatively high precedence and should be shared.
group_vars/all.yml:
my_timestamp: "{{ ansible_date_time.date }}{{ ansible_date_time.hour }}{{ ansible_date_time.minute }}{{ ansible_date_time.second }}"
When tried, the values were different across hosts, making my directory structure inconsistent.
I suspect this is because the variable is only evaluated lazily, when the referred ansible_date_time object already has a different value on each host, depending on the exact moment execution reaches the variable reference and resolves the value.
The same issue happens when I try to set_fact in my playbook, at the very beginning.
site.yml:
---
# This playbook performs the deployment
- name: Prepare playbook settings
hosts: all
tasks:
- name: Generate my timestamp
set_fact:
my_timestamp: "{{ ansible_date_time.date }}{{ ansible_date_time.hour }}{{ ansible_date_time.minute }}{{ ansible_date_time.second }}"
The question is: how could I set a constant, shared timestamp, which is the same on all nodes during the whole execution of a playbook? What would be the clean Ansible way of generating a consistent, constant time-stamp? Without passing as a command line argument, printing to a file and the reading back the value etc.
I am on Ansible 2.9.23.