You're using the "debug:" module to set the "msg" variable so the date
value isn't in the "{{ msg }}" variable, rather it's in the "{{ msg.msg }}"
variable.
Try these lines in stead:
- name: FIXED - age of file in days stored in msg
set_fact:
msg: "{{ (ansible_date_time.epoch|int -
file_age.stat.mtime|int)/(86400|round|int) }}"
- name: FIXED - Show msg
debug:
var: msg
- name: FIXED - Show msg as integer
debug:
msg: " Your file is {{ msg|int }} days old"
That then stores the computation done in the "set_fact:" module in the
"msg" variable as expected.
On Thursday, May 2, 2019 at 6:30:10 AM UTC-5, Andy Magana wrote:
>
> 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/0665a41c-808d-44e6-a076-d92b69b4839b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.