def __init__(self, project): """ Setup Parser Modules @project is a relative or absolute path to an Ansible Project """ self.ansiblecfg = AnsibleCfg(project) self.roleparser = RoleParser(self.ansiblecfg.get_role_paths()) self.playbookparser = PlaybookParser( self.ansiblecfg.get_playbook_paths()) # Parse all playbooks self.playbookparser.parse_playbooks()
def __init__(self, project): """ Setup Parser Modules @param project: is a relative or absolute path to an Ansible Project """ self.ansiblecfg = AnsibleCfg(project) print("Parsing roles") self.roleparser = RoleParser(self.ansiblecfg.get_role_paths()) print("Parsing playbooks") self.playbookparser = PlaybookParser( self.ansiblecfg.get_playbook_paths()) print("Parsing hosts") self.hostVarsParser = HostVarsParser(self.ansiblecfg.get_hosts_paths()) # Parse all playbooks self.hostVarsParser.parse_hosts_vars() self.playbookparser.parse_playbooks()
class DirParser(object): """ Parses an Ansible Project Directory Structure """ def __init__(self, project): """ Setup Parser Modules @project is a relative or absolute path to an Ansible Project """ self.ansiblecfg = AnsibleCfg(project) self.roleparser = RoleParser(self.ansiblecfg.get_role_paths()) self.playbookparser = PlaybookParser( self.ansiblecfg.get_playbook_paths()) # Parse all playbooks self.playbookparser.parse_playbooks() def get_parserdata(self): """ This function returns a datastructure that can be passed to a formatter """ return self.playbookparser.parserdata + self.roleparser.parserdata
class DirParser(object): """ Parses an Ansible Project Directory Structure """ def __init__(self, project): """ Setup Parser Modules @param project: is a relative or absolute path to an Ansible Project """ self.ansiblecfg = AnsibleCfg(project) print("Parsing roles") self.roleparser = RoleParser(self.ansiblecfg.get_role_paths()) print("Parsing playbooks") self.playbookparser = PlaybookParser( self.ansiblecfg.get_playbook_paths()) print("Parsing hosts") self.hostVarsParser = HostVarsParser(self.ansiblecfg.get_hosts_paths()) # Parse all playbooks self.hostVarsParser.parse_hosts_vars() self.playbookparser.parse_playbooks() def get_paths(self): return { 'role': self.ansiblecfg.get_role_paths(), 'playbooks': [self.ansiblecfg.get_playbook_paths()], 'host': self.ansiblecfg.get_hosts_paths() } def get_parserdata(self): """ This function returns a datastructure that can be passed to a formatter """ return { 'playbooks': self.playbookparser.parserdata, 'roles': self.roleparser.parserdata, 'host_vars': self.hostVarsParser.parserdata }
def test_ansiblecfg(self): localdir = os.path.dirname(os.path.realpath(__file__)) testfile = os.path.join(localdir, ".output/ansible.cfg") with open(testfile, "w") as f: f.write("\n roles_path = role1:role2\n") ansiblecfg = AnsibleCfg(os.path.dirname(testfile)) assert("roles_path" in ansiblecfg.settings) assert("role1" in ansiblecfg.settings["roles_path"]) assert("role2" in ansiblecfg.settings["roles_path"])