40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import sys
|
|
import yaml
|
|
import argparse
|
|
from datetime import datetime
|
|
from .excel_reader import read_servers, read_flows
|
|
from .inventory import generate_inventory
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="Convert WIF Excel to Ansible Inventory")
|
|
parser.add_argument("wif_file", help="Path to the WIF Excel file (.xlsx)")
|
|
parser.add_argument("--output", "-o", help="Output YAML file path", default=None)
|
|
|
|
args = parser.parse_args()
|
|
|
|
print(f"Reading servers from {args.wif_file}...")
|
|
servers = read_servers(args.wif_file)
|
|
print(f"Found {len(servers)} servers in allowlist.")
|
|
|
|
print(f"Reading flows...")
|
|
flows = read_flows(args.wif_file, servers)
|
|
print(f"Found {len(flows)} raw flows.")
|
|
|
|
print("Generating inventory...")
|
|
inventory = generate_inventory(servers, flows)
|
|
|
|
# Determine output filename
|
|
if args.output:
|
|
outfile = args.output
|
|
else:
|
|
timestamp = datetime.now().strftime("%Y-%m-%d_%H%M")
|
|
outfile = f"inventory_{timestamp}.yml"
|
|
|
|
with open(outfile, 'w') as f:
|
|
yaml.dump(inventory, f, default_flow_style=False)
|
|
|
|
print(f"Successfully wrote inventory to {outfile}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|