Ejemplo n.º 1
0
    def get_action_tasks(candidate, settings):
        tasks = []
        errors = []

        if not candidate.faulty:
            try:
                with codecs.open(candidate.path, mode="rb",
                                 encoding="utf-8") as f:
                    yamllines = parse_yaml_linenumbers(f, candidate.path)

                if yamllines:
                    tasks = action_tasks(yamllines, candidate)
            except LaterError as ex:
                e = ex.original
                errors.append(
                    StandardBase.Error(
                        e.problem_mark.line + 1,
                        "syntax error: {msg}".format(msg=e.problem)))
                candidate.faulty = True
            except LaterAnsibleError as e:
                errors.append(
                    StandardBase.Error(e.line,
                                       "syntax error: {}".format(e.message)))
                candidate.faulty = True

        return tasks, errors
Ejemplo n.º 2
0
    def get_normalized_tasks(candidate, settings, full=False):
        normalized = []
        errors = []

        if not candidate.faulty:
            try:
                with codecs.open(candidate.path, mode="rb",
                                 encoding="utf-8") as f:
                    yamllines = parse_yaml_linenumbers(f, candidate.path)

                if yamllines:
                    tasks = action_tasks(yamllines, candidate)
                    for task in tasks:
                        # An empty `tags` block causes `None` to be returned if
                        # the `or []` is not present - `task.get("tags", [])`
                        # does not suffice.

                        # Deprecated.
                        if "skip_ansible_lint" in (task.get("tags")
                                                   or []) and not full:
                            # No need to normalize_task if we are skipping it.
                            continue

                        if "skip_ansible_later" in (task.get("tags")
                                                    or []) and not full:
                            # No need to normalize_task if we are skipping it.
                            continue

                        normalized.append(
                            normalize_task(
                                task, candidate.path,
                                settings["ansible"]["custom_modules"]))

            except LaterError as ex:
                e = ex.original
                errors.append(
                    StandardBase.Error(
                        e.problem_mark.line + 1,
                        "syntax error: {msg}".format(msg=e.problem)))
                candidate.faulty = True
            except LaterAnsibleError as e:
                errors.append(
                    StandardBase.Error(
                        e.line, "syntax error: {msg}".format(msg=e.message)))
                candidate.faulty = True

        return normalized, errors