Created
September 14, 2015 15:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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