def _build_node_data_bag(): """Builds one 'node' data bag item per file found in the 'nodes' directory Automatic attributes for a node item: 'id': It adds data bag 'id', same as filename but with underscores 'name': same as the filename 'fqdn': same as the filename (LittleChef filenames should be fqdns) 'hostname': Uses the first part of the filename as the hostname (until it finds a period) minus the .json extension 'domain': filename minus the first part of the filename (hostname) minus the .json extension In addition, it will contain the merged attributes from: All default cookbook attributes corresponding to the node All attributes found in nodes/<item>.json file Default and override attributes from all roles Returns the node object of the node which is about to be configured, or None if this node object cannot be found. """ current_node = None nodes = lib.get_nodes() node_data_bag_path = os.path.join('data_bags', 'node') # In case there are leftovers _remove_local_node_data_bag() os.makedirs(node_data_bag_path) all_recipes = lib.get_recipes() all_roles = lib.get_roles() for node in nodes: # Dots are not allowed (only alphanumeric), substitute by underscores node['id'] = node['name'].replace('.', '_') # Build extended role list node['role'] = lib.get_roles_in_node(node) node['roles'] = node['role'][:] for role in node['role']: node['roles'].extend(lib.get_roles_in_role(role)) node['roles'] = list(set(node['roles'])) # Build extended recipe list node['recipes'] = lib.get_recipes_in_node(node) # Add recipes found inside each roles in the extended role list for role in node['roles']: node['recipes'].extend(lib.get_recipes_in_role(role)) node['recipes'] = list(set(node['recipes'])) # Add node attributes _add_merged_attributes(node, all_recipes, all_roles) _add_automatic_attributes(node) # Save node data bag item with open( os.path.join('data_bags', 'node', node['id'] + '.json'), 'w') as f: f.write(json.dumps(node)) if node['name'] == env.host_string: current_node = node return current_node
def _build_node_data_bag(): """Builds one 'node' data bag item per file found in the 'nodes' directory Automatic attributes for a node item: 'id': It adds data bag 'id', same as filename but with underscores 'name': same as the filename 'fqdn': same as the filename (LittleChef filenames should be fqdns) 'hostname': Uses the first part of the filename as the hostname (until it finds a period) minus the .json extension 'domain': filename minus the first part of the filename (hostname) minus the .json extension In addition, it will contain the merged attributes from: All default cookbook attributes corresponding to the node All attributes found in nodes/<item>.json file Default and override attributes from all roles Returns the node object of the node which is about to be configured, or None if this node object cannot be found. """ current_node = None nodes = lib.get_nodes() node_data_bag_path = os.path.join('data_bags', 'node') # In case there are leftovers _remove_local_node_data_bag() os.makedirs(node_data_bag_path) all_recipes = lib.get_recipes() all_roles = lib.get_roles() for node in nodes: # Dots are not allowed (only alphanumeric), substitute by underscores node['id'] = node['name'].replace('.', '_') # Build extended role list node['role'] = lib.get_roles_in_node(node) node['roles'] = node['role'][:] for role in node['role']: node['roles'].extend(lib.get_roles_in_role(role)) node['roles'] = list(set(node['roles'])) # Build extended recipe list node['recipes'] = lib.get_recipes_in_node(node) # Add recipes found inside each roles in the extended role list for role in node['roles']: node['recipes'].extend(lib.get_recipes_in_role(role)) node['recipes'] = list(set(node['recipes'])) # Add node attributes _add_merged_attributes(node, all_recipes, all_roles) _add_automatic_attributes(node) # Save node data bag item with open(os.path.join( 'data_bags', 'node', node['id'] + '.json'), 'w') as f: f.write(json.dumps(node)) if node['name'] == env.host_string: current_node = node return current_node
def _build_node_data_bag(): """Builds one 'node' data bag item per file found in the 'nodes' directory Attributes for a node item: 'id': It adds data bag 'id' using the first part of the filename (until it finds a period) minus the .json extension 'name': same as the filename 'fqdn': same as the filename (as LittleChef filenames should be fqdns) 'hostname': same as the filename all attributes found in nodes/<item>.json file Returns the node object of the node which is about to be configured, or None if this node object cannot be found. """ current_node = None nodes = lib.get_nodes() node_data_bag_path = os.path.join('data_bags', 'node') _remove_node_data_bag() os.makedirs(node_data_bag_path) all_recipes = lib.get_recipes() all_roles = lib.get_roles() for node in nodes: node['id'] = node['name'].split('.')[0] # Build extended role list node['role'] = lib.get_roles_in_node(node) node['roles'] = node['role'][:] for role in node['role']: node['roles'].extend(lib.get_roles_in_role(role)) node['roles'] = list(set(node['roles'])) # Build extended recipe list node['recipes'] = lib.get_recipes_in_node(node) # Add recipes found inside each roles in the extended role list for role in node['roles']: node['recipes'].extend(lib.get_recipes_in_role(role)) node['recipes'] = list(set(node['recipes'])) # Add node attributes _add_merged_attributes(node, all_recipes, all_roles) _add_automatic_attributes(node) # Save node data bag item with open(os.path.join( 'data_bags', 'node', node['id'] + '.json'), 'w') as f: f.write(json.dumps(node)) if node['name'] == env.host_string: current_node = node return current_node
def build_node_data_bag(): """Builds one 'node' data bag item per file found in the 'nodes' directory Automatic attributes for a node item: 'id': It adds data bag 'id', same as filename but with underscores 'name': same as the filename 'fqdn': same as the filename (LittleChef filenames should be fqdns) 'hostname': Uses the first part of the filename as the hostname (until it finds a period) minus the .json extension 'domain': filename minus the first part of the filename (hostname) minus the .json extension In addition, it will contain the merged attributes from: All default cookbook attributes corresponding to the node All attributes found in nodes/<item>.json file Default and override attributes from all roles """ nodes = lib.get_nodes() node_data_bag_path = os.path.join("data_bags", "node") # In case there are leftovers remove_local_node_data_bag() os.makedirs(node_data_bag_path) all_recipes = lib.get_recipes() all_roles = lib.get_roles() for node in nodes: # Dots are not allowed (only alphanumeric), substitute by underscores node["id"] = node["name"].replace(".", "_") # Build extended role list node["role"] = lib.get_roles_in_node(node) node["roles"] = node["role"][:] for role in node["role"]: node["roles"].extend(lib.get_roles_in_role(role)) node["roles"] = list(set(node["roles"])) # Build extended recipe list node["recipes"] = lib.get_recipes_in_node(node) # Add recipes found inside each roles in the extended role list for role in node["roles"]: node["recipes"].extend(lib.get_recipes_in_role(role)) node["recipes"] = list(set(node["recipes"])) # Add node attributes _add_merged_attributes(node, all_recipes, all_roles) _add_automatic_attributes(node) # Save node data bag item with open(os.path.join("data_bags", "node", node["id"] + ".json"), "w") as f: f.write(json.dumps(node))