Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cinek810/0048badf55b3f9c36d4290ae4376b734 to your computer and use it in GitHub Desktop.
Save cinek810/0048badf55b3f9c36d4290ae4376b734 to your computer and use it in GitHub Desktop.
ansible-review standard checking if all tasks in role are tagged with "role_ROLENAME"
import re
def check_role_tag(candidate,setting):
result = Result(candidate.path)
pathSpliter = re.compile("roles/([a-zA-Z0-9_\-]+)/tasks/main.yml")
splittedPath = pathSpliter.match(candidate.path)
if splittedPath is not None:
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 "role_"+splittedPath.group(1) not in task["tags"]:
result.errors.append(Error(task['__line__'],"Missing tag is role_"+splittedPath.group(1)))
return result
all_tasks_in_role_has_tag = Standard(dict(
name = "All tasks in role X should have role_X tag",
check = check_role_tag,
types = [ 'task' ] ,
version = "0.1"
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment