Skip to content

Instantly share code, notes, and snippets.

@omsai
Last active May 25, 2017 00:37
Show Gist options
  • Save omsai/e757aeea8c3e9a588a095422433324c4 to your computer and use it in GitHub Desktop.
Save omsai/e757aeea8c3e9a588a095422433324c4 to your computer and use it in GitHub Desktop.
# Pariksheet Nanda <hpc@uconn.edu> 2017
#
# License: CC0 Public Domain
#
# To the extent possible under law, Pariksheet Nanda has waived all copyright
# and related or neighboring rights to host.py
from __future__ import print_function
from ansible.errors import AnsibleError
try:
from ClusterShell import NodeSet
HAS_LIB = True
except ImportError:
HAS_LIB = False
def fold(hosts):
''' Fold a list of hostnames. Example:
-debug: msg="{{ groups.foo | fold }}"
'''
if not HAS_LIB:
raise AnsibleError('You need to install "clustershell" prior to '
'running the fold filter')
node_set = NodeSet.NodeSet()
for host in hosts:
node_set.update(host)
return node_set
class FilterModule(object):
''' Hosts filter '''
def filters(self):
return {
'fold': fold
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment