Last active
May 1, 2019 20:57
-
-
Save mrlesmithjr/0c59c647a615dec03b4b0e2da2d0fdc4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
--- | |
- hosts: localhost | |
gather_facts: true | |
connection: local | |
# user: ansible | |
# become: true | |
vars: | |
# Define path to file to check | |
# file_to_check: /etc/ansible/ansible.cfg | |
# file_to_check: $HOME/ansible.cfg | |
file_to_check: ansible.cfg | |
tasks: | |
- name: get the file | |
stat: | |
path: "{{ file_to_check }}" | |
register: file_info | |
- name: Set last modification of {{ file_to_check }} time in epoch | |
set_fact: | |
last_modified: "{{ file_info['stat']['mtime'] }}" | |
- name: Display last modified time of {{ file_to_check }} in epoch | |
debug: | |
var: last_modified | |
- name: Set current time in epoch | |
set_fact: | |
current_time: "{{ ansible_date_time['epoch']|int }}" | |
- name: Displaying current time in epoch | |
debug: | |
var: current_time | |
- name: Set time since {{ file_to_check }} was last modified | |
set_fact: | |
last_modified_from_current_time: "{{ (current_time|int - last_modified|int) }}" | |
- name: Display number of days since {{ file_to_check }} was last modified | |
debug: | |
msg: "Has been {{ (last_modified_from_current_time|int/86400)|round(0,'floor') }} of days since last update" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment