Saltstack Official Linux Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 line
481B

  1. # -*- coding: utf-8 -*-
  2. '''
  3. Module for defining new filter for sorting
  4. host names/alias by FQDN first and alphabetically
  5. '''
  6. from jinja2 import Undefined
  7. def __virtual__():
  8. return 'linux_hosts'
  9. def fqdn_sort_fn(n1):
  10. length = len(n1)
  11. return length
  12. def fqdn_sort_filter(iterable):
  13. if iterable is None or isinstance(iterable, Undefined):
  14. return iterable
  15. # Do effective custom sorting of iterable here
  16. return sorted(set(iterable), key=fqdn_sort_fn)