So I have resolved my issue thanks to others advice what worked is to 
1. stat the file get its mtime and
2. register and 
3. assign it to a variable and the same for the current date and 
4. put both variables  and include to convert them to an INT into a jinja 
subtraction arithmetic and divide all inside the jinja {{ }}
5. register the sum total and include the INT
6. add another debug and msg to output SUM as a whole number instead of a 
float. 





[root@ansible ansible]# ansible-playbook mystat.yml 

PLAY [localhost] 
*****************************************************************************************************************

TASK [Gathering Facts] 
***********************************************************************************************************
ok: [localhost]

TASK [stat] 
**********************************************************************************************************************
ok: [localhost]

TASK [debug] 
*********************************************************************************************************************
ok: [localhost] => {
    "file_age.stat.mtime": "1556662665.1"
}

TASK [debug] 
*********************************************************************************************************************
ok: [localhost] => {
    "ansible_date_time.epoch": "1556746971"
}

TASK [age of file in days] 
*******************************************************************************************************
ok: [localhost] => {
    "msg": "0.975763888889"
}

TASK [debug] 
*********************************************************************************************************************
ok: [localhost] => {
    "msg": {
        "changed": false, 
        "failed": false, 
        "msg": "0.975763888889"
    }
}

TASK [debug] 
*********************************************************************************************************************
ok: [localhost] => {
    "msg": " Your file is 0 days old"
}

PLAY RECAP 
***********************************************************************************************************************
localhost                  : ok=7    changed=0    unreachable=0    failed=0 
  

[root@ansible ansible]# 

AND my playbook looks like this above is the results. 


---
- hosts: localhost
  user: ansible
  become: true
  tasks:
  - stat:
      path: /etc/ansible/ansible.cfg
    register: file_age

  - debug:
      var: file_age.stat.mtime

  - debug:
      var: ansible_date_time.epoch

  - name: age of file in days
    debug:
      msg: "{{ (ansible_date_time.epoch|int - 
file_age.stat.mtime|int)/(86400|round|int) }}"
    register: msg

  - debug:
      var: msg

  - debug:
      msg: " Your file is {{ msg|int }} days old"
~                                                                           
  



On Wednesday, May 1, 2019 at 9:51:06 PM UTC-5, [email protected] wrote:
>
> It's hard without the actual playbook, but I think you need to use 
> 'current.stdout' inserted of just 'current' in that last task.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c565a55f-0d6f-49c3-b7a6-8ffa7f55ab40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to