Created
December 15, 2018 22:07
-
-
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"
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 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