|
|
@ -1,6 +1,7 @@
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
import yaml
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
|
|
|
@ -117,6 +118,12 @@ def _read_yaml(path):
|
|
|
|
except yaml.YAMLError as e:
|
|
|
|
except yaml.YAMLError as e:
|
|
|
|
return AnsibleError(e)
|
|
|
|
return AnsibleError(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GROUPS_PATTERN_OPS = {
|
|
|
|
|
|
|
|
"": lambda old, add: old | add,
|
|
|
|
|
|
|
|
"!": lambda old, add: old - add,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GROUPS_PATTERN_OPS_NAMES = "".join(GROUPS_PATTERN_OPS.keys())
|
|
|
|
|
|
|
|
GROUPS_PATTERN = re.compile(r'^(?P<operation>[' + GROUPS_PATTERN_OPS_NAMES + r']?)(?P<group_name>[^' + GROUPS_PATTERN_OPS_NAMES + r'].*)$')
|
|
|
|
def _parse_group_aliasses(inv, data):
|
|
|
|
def _parse_group_aliasses(inv, data):
|
|
|
|
for group, syntax in data.items():
|
|
|
|
for group, syntax in data.items():
|
|
|
|
if isinstance(syntax, str):
|
|
|
|
if isinstance(syntax, str):
|
|
|
@ -131,10 +138,10 @@ def _parse_group_aliasses(inv, data):
|
|
|
|
group_list.insert(0, 'all') # remove group from all for inversion
|
|
|
|
group_list.insert(0, 'all') # remove group from all for inversion
|
|
|
|
hosts = set()
|
|
|
|
hosts = set()
|
|
|
|
for group_name in group_list:
|
|
|
|
for group_name in group_list:
|
|
|
|
if group_name[0] == '!':
|
|
|
|
group_matched = GROUPS_PATTERN.match(group_name)
|
|
|
|
hosts -= inv.all_hosts_of_group(group_name[1:])
|
|
|
|
add = inv.all_hosts_of_group(group_matched.group('group_name'))
|
|
|
|
else:
|
|
|
|
op = GROUPS_PATTERN_OPS[group_matched.group('operation')]
|
|
|
|
hosts |= inv.all_hosts_of_group(group_name)
|
|
|
|
hosts = op(hosts, add)
|
|
|
|
inv.add_hosts_to_group(hosts, group)
|
|
|
|
inv.add_hosts_to_group(hosts, group)
|
|
|
|
|
|
|
|
|
|
|
|
def _parse_groups(inv, data):
|
|
|
|
def _parse_groups(inv, data):
|
|
|
|