Evaluating variables

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:

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!