diff --git a/enc.py b/enc.py index 55217ed..343ac32 100755 --- a/enc.py +++ b/enc.py @@ -1,4 +1,13 @@ #!/usr/bin/env python +""" +External Node Classifier (ENC) for Puppet. + +It reads in YAML files located at '/opt/puppetlabs/enc/data'. + +If the environment specified in the YAML file is 'testing', +the environment is not included in the output. +""" + import sys import yaml @@ -17,18 +26,20 @@ def main(): # 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) + data = yaml.safe_load(f) + + # If the environment is 'testing', remove it from the output + if data.get("environment") == "testing": + data.pop("environment", None) + + # Print the YAML without the 'environment' if it was 'testing' + print(yaml.dump(data)) except IOError as e: print("Could not open {}: {}".format(file_path, e), file=sys.stderr) sys.exit(1) + except yaml.YAMLError as e: + print("Error in {}: {}".format(file_path, e), file=sys.stderr) + sys.exit(1) if __name__ == "__main__": diff --git a/enc_update b/enc_update deleted file mode 100755 index 5f833c1..0000000 --- a/enc_update +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/bash - -# open a subshell and pull enc data -( - cd /opt/puppetlabs/enc/ - git reset --hard master - git clean -fd - git pull -)