def generate_group_vars_all(self):
path = 'result/{}/group_vars/all'.format(self.grid_name)
variables = AutoDict()
hosts_entries = AutoDict()
for group in self.current_groups:
for ip in group.groupips.split(','):
hostname = ip.replace('.','-')
host = '{}.node.{}'.format(hostname, self.grid_name)
hosts_entries['hosts'][str(host)] = str(ip)
for ip in self.current_config.mastersips.split(','):
hostname = ip.replace('.','-')
host = '{}.node.{}'.format(hostname, self.grid_name)
hosts_entries['hosts'][str(host)] = str(ip)
terminal_ip = self.current_config.terminalips.split(',')[1]
terminal_hostname = terminal_ip.replace('.','-')
terminal_host = '{}.node.{}'.format(terminal_hostname, self.grid_name)
hosts_entries['hosts'][str(terminal_host)] = str(terminal_ip)
variables['hosts'] = json.dumps(hosts_entries['hosts'])
variables['grid_name'] = self.current_grid.name
variables['terminal_ip'] = self._nameserver()
self._generate_template(path, variables)
vars_json = json.loads(self.current_config.vars)
vars_yaml = yaml.safe_dump(vars_json, default_flow_style=False)
with open(path, "a") as yaml_file:
yaml_file.write(vars_yaml)
评论列表
文章目录