Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cinek810/1a7a2b6d211aa90f5ffcb4a6ecf6943c to your computer and use it in GitHub Desktop.
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)
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