-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsplit.py
More file actions
22 lines (19 loc) · 718 Bytes
/
split.py
File metadata and controls
22 lines (19 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from ansible import errors
import re
def split_string(string, separator=' '):
try:
return string.split(separator)
except Exception, e:
raise errors.AnsibleFilterError('split plugin error: %s, provided string: "%s"' % str(e),str(string) )
def split_regex(string, separator_pattern='\s+'):
try:
return re.split(separator_pattern, string)
except Exception, e:
raise errors.AnsibleFilterError('split plugin error: %s, provided string: "%s"' % str(e),str(string) )
class FilterModule(object):
''' A filter to split a string into a list. '''
def filters(self):
return {
'split' : split_string,
'split_regex' : split_regex,
}