Last active
May 25, 2017 00:37
-
-
Save omsai/e757aeea8c3e9a588a095422433324c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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