From 5fc50d750a87e206cf555f8b2e9c0931b0ab9f92 Mon Sep 17 00:00:00 2001 From: David Whiteside Date: Tue, 4 Aug 2015 07:32:38 -0600 Subject: [PATCH] added prevension of infinate recursion which is possible with this feature. #fixed #5 --- lib/ansibledocgen/parser/playbook.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/ansibledocgen/parser/playbook.py b/lib/ansibledocgen/parser/playbook.py index f4d6d0c..66ede9a 100644 --- a/lib/ansibledocgen/parser/playbook.py +++ b/lib/ansibledocgen/parser/playbook.py @@ -1,6 +1,7 @@ """ Playbook Module """ import yaml import re +import os class PlaybookParser(object): @@ -13,6 +14,8 @@ def __init__(self, playbooks, is_role=False): self.playbooks = playbooks self.parserdata = [] self.is_role = is_role + # basename of playbooks already parsed, to prevent infinate recrusion + self.already_parsed_playbooks = [] def parse_playbooks(self): """ Parse Each Playbook """ @@ -29,6 +32,16 @@ def parse_playbook(self, playbook): if m: rolename = m.group(1) + # Do Not Parse If Its Already been Parsed + playbook_base = os.path.basename(playbook) + if self.is_role: + # If Role, prepend rolename to make file unique to role + playbook_base = os.path.join(rolename, playbook_base) + # Check if this file has alread been parsed + if playbook_base in self.already_parsed_playbooks: + return + self.already_parsed_playbooks.append(playbook_base) + # Setup Playbook Metadata playbookentry = {} playbookentry["relative_path"] = playbook