Skip to content

Instantly share code, notes, and snippets.

@bubba-h57
Created September 14, 2015 15:16
Show Gist options
  • Save bubba-h57/f1e464401dd767537f10 to your computer and use it in GitHub Desktop.
Save bubba-h57/f1e464401dd767537f10 to your computer and use it in GitHub Desktop.
Sometimes I need a timestamp string in Ansible. Specifically, I need the same timestamp string available across all my hosts. This seems like the most elegant way to achieve that.
---
- name: "Get Timestamp on Local Host"
hosts: localhost
gather_facts: False
tasks:
- name: "Setting Time Stamp"
set_fact:
time_stamp: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"
- name: "Now we can go to work."
hosts: webservers
gather_facts: True
pre_tasks:
- name: "Add the Stamp to each Host"
set_fact:
time_stamp: "{{ hostvars['localhost'].time_stamp}}"
roles:
- Timestamp_Role
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment