Calculate partition space used in jinja

I have a playbook that uses gather facts, then I use the ansible_mounts fact in a jinja2 template. In this template, I can print out each partition, the total size and total available. What I’d like to do is to also calculate the percentage of space available. I’m trying below, but keep getting a templating error when the playbook runs. Any ideas?

server_mounts.html.j2

Partition/Mount Space Report

{{ now(false, ‘%m/%d/%Y %I:%M:%S’) }}

What is the error you get ?

My apologies. I obviously forgot to add the error. I did find that I was missing a ‘)’ character at the end of the “Total Space” line. But now I get the following:

FAILED! => {“changed”: false, “msg”: “AnsibleUndefinedVariable: ‘dict object’ has no attribute ‘size’”}

The j2 file is above, but here’s the playbook I’m using:

My apologies. I obviously forgot to add the error. I did find that I was missing a ')' character at the end of the "Total Space" line. But now I get the following:

FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'size'"}

The j2 file is above, but here's the playbook I'm using:

---
- hosts: localhost
become: true
become_method: sudo
gather_facts: yes

tasks:

- name: Print out server mounts
template:
src: /root/server_mounts.html.j2
dest: /var/tmp/server_mounts.html
delegate_to: localhost
run_once: true

I can't find why its complaining about a "size" attribute.

Hello Harry,

I don't see that problem either, are you really sure that the you posted the content of /root/server_mounts.html.j2?

BTW: That's a really weird location for any part of your Ansible project if you ask me.

Regards
          Racke