Merge pull request 'Merge pull request 'Changed prodinf01n01 to testing environment' (#6) from change_prodinf01n01_to_testing into master' (#7) from feature/testingenv into master

Reviewed-on: #7
This commit is contained in:
Ben Vincent 2023-06-21 21:31:04 +09:30
commit 74b9011d7d
2 changed files with 20 additions and 18 deletions

29
enc.py
View File

@ -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__":

View File

@ -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
)