def generate_group_vars_all(self):
path = 'result/{}/group_vars/all'.format(self.grid_name)
variables = AutoDict()
hosts_entries = AutoDict()
with open('result/{}/infrastructure/terraform.tfstate'.format(self.grid_name), 'r') as json_file:
json_data = json.load(json_file)
for module in json_data['modules']:
for resource, value in module['resources'].iteritems():
if value['type'] == 'aws_instance':
hostname = value['primary']['attributes']['private_dns'].split('.')[0]
host = '{}.node.{}'.format(hostname, self.grid_name)
ip = value['primary']['attributes']['private_ip']
hosts_entries['hosts'][str(host)] = str(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)
评论列表
文章目录