# Evaluating variables

**URL:** <https://forum.ansible.com/t/evaluating-variables/13839>\
**Category:** Ansible Project\
**Created:** [November 4, 2013, 4:51pm UTC](https://forum.ansible.com/t/evaluating-variables/13839 "2013-11-04T16:51:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathieu\_Guillaume](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Mathieu\_Guillaume](https://forum.ansible.com/u/Mathieu_Guillaume)\
**Post date:** [November 4, 2013, 4:51pm UTC](https://forum.ansible.com/t/evaluating-variables/13839/1 "2013-11-04T16:51:54Z")

</div>

I was wondering if there was some way to “evaluate” variables (like the python eval function).

For instance, I have one use case where I set shared memory for PostgreSQL as “2GB” and want to adapt the kernel.shmmax to fit it.  
So, I want to take the “2GB” variable, add a base “128MB” to it, convert to bytes in a new variable and use that to put in sysctl.conf.

Using jinja2 filters, I can express it as a math expression, but I can’t find a way to evaluate the result.  
An example playbook would be:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 4, 2013, 11:30pm UTC](https://forum.ansible.com/t/evaluating-variables/13839/2 "2013-11-04T23:30:14Z")

</div>

You can use the set\_fact module to store variables as the result of an evaluation.

I should point out though that Ansible likes to keep things simple, and would prefer to not see that in a Playbook.

It would be a great opportunity to write a simple lookup plugin of your own, perhaps!
