#!/usr/bin/env python import sys import yaml def main(): # Get the hostname from the command line arguments if len(sys.argv) != 2: print("Usage: {} ".format(sys.argv[0]), file=sys.stderr) sys.exit(1) hostname = sys.argv[1] # Construct the file path file_path = "/opt/puppetlabs/enc/data/{}.yaml".format(hostname) # Try to open and read the YAML file try: with open(file_path, "r") as f: file_content = f.read() try: # Parse the YAML file yaml.safe_load(file_content) # If correctly parsed, print the raw content print(file_content) except yaml.YAMLError as e: print("Error in {}: {}".format(file_path, e), file=sys.stderr) sys.exit(1) except IOError as e: print("Could not open {}: {}".format(file_path, e), file=sys.stderr) sys.exit(1) if __name__ == "__main__": main()