Skip to content

Instantly share code, notes, and snippets.

@maxim
Created July 7, 2014 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxim/eef32d24ecc07ab17bec to your computer and use it in GitHub Desktop.
Save maxim/eef32d24ecc07ab17bec to your computer and use it in GitHub Desktop.
from jinja2 import contextfilter
class FilterModule(object):
''' Extra filters '''
def filters(self):
return {
'percent_of': self.percent_of,
'of_ram': self.of_ram
}
@contextfilter
def of_ram(self, ctx, percent):
return self.percent_of(percent, ctx.resolve('ansible_memtotal_mb'))
def percent_of(self, percent, total):
return (total * (float(str(percent).strip('%')) / 100.0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment