Created
February 16, 2024 00:45
-
-
Save thejimnicholson/2d2748b68d57c01f43ab3bd2ee7dcb4d to your computer and use it in GitHub Desktop.
stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
def process_yaml_file(input_file): | |
with open(input_file, 'r') as file: | |
data = yaml.safe_load(file) | |
group_entries = {} | |
for entry_name, entry_data in data.items(): | |
hostgroups = entry_data.get('hostgroups', []) | |
for group_name in hostgroups: | |
if group_name not in group_entries: | |
group_entries[group_name] = [] | |
group_entries[group_name].append({entry_name: entry_data}) | |
for group_name, entries in group_entries.items(): | |
output_file = f"{group_name}_entries.yaml" | |
with open(output_file, 'w') as file: | |
yaml.dump_all(entries, file, default_flow_style=False) | |
print(f"File '{output_file}' created with entries for group '{group_name}'.") | |
if __name__ == "__main__": | |
input_file = "your_yaml_file.yaml" | |
process_yaml_file(input_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment