Created
December 15, 2018 22:10
-
-
Save cinek810/1a7a2b6d211aa90f5ffcb4a6ecf6943c to your computer and use it in GitHub Desktop.
ansible-review standard checking if service is restarted in task (funinit.wordpress.com)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def check_service_restart(candidate,setting): | |
result = Result(candidate.path) | |
with codecs.open(candidate.path, mode='rb', encoding='utf-8') as f: | |
tasks = parse_yaml_linenumbers(f.read(), candidate.path) | |
for task in tasks: | |
if "service" in task and task["service"]["state"] is not None and task["service"]["state"] == "restarted": | |
result.errors.append(Error(task["__line__"],json.dumps(task["service"],indent=4))) | |
return result | |
task_should_not_restart_service = Standard(dict( | |
name = "Service should not be restarted in tasks", | |
check = check_service_restart, | |
types = [ 'task' ], | |
version = "0.1" | |
)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment