# Calculate partition space used in jinja

**URL:** <https://forum.ansible.com/t/calculate-partition-space-used-in-jinja/36016>\
**Category:** Ansible Project\
**Created:** [November 19, 2021, 8:44pm UTC](https://forum.ansible.com/t/calculate-partition-space-used-in-jinja/36016 "2021-11-19T20:44:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [November 19, 2021, 8:44pm UTC](https://forum.ansible.com/t/calculate-partition-space-used-in-jinja/36016/1 "2021-11-19T20:44:06Z")

</div>

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’) }}

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [November 20, 2021, 6:10am UTC](https://forum.ansible.com/t/calculate-partition-space-used-in-jinja/36016/2 "2021-11-20T06:10:25Z")

</div>

What is the error you get ?

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [November 22, 2021, 1:19pm UTC](https://forum.ansible.com/t/calculate-partition-space-used-in-jinja/36016/3 "2021-11-22T13:19:35Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [November 22, 2021, 1:53pm UTC](https://forum.ansible.com/t/calculate-partition-space-used-in-jinja/36016/4 "2021-11-22T13:53:38Z")

</div>

> 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  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
