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:
commit
74b9011d7d
29
enc.py
29
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__":
|
||||
|
||||
@ -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
|
||||
)
|
||||
Loading…
Reference in New Issue
Block a user