puppet-enc/enc.py
2023-06-17 20:30:19 +10:00

26 lines
666 B
Python

#!/usr/bin/env python3
import yaml
import os
import sys
# Path to your ENC data directory
enc_data_dir = '/opt/puppetlabs/enc/data'
# Get the hostname from command line argument
hostname = sys.argv[1]
# Construct the file path
file_path = os.path.join(enc_data_dir, f'{hostname}.yaml')
# Check if the file exists
if os.path.exists(file_path):
# If the file exists, open it and load the YAML data
with open(file_path, 'r') as file:
data = yaml.safe_load(file)
print(yaml.dump(data))
else:
# If the file does not exist, print an error message and exit
sys.stderr.write(f"Error: File {file_path} does not exist.\n")
sys.exit(1)