lib/ansiblelint/utils.py
def append_skipped_rules(pyyaml_data, file_text, file_type):
    """ Uses ruamel.yaml to parse comments then adds a
        skipped_rules list to the task (or meta yaml block)
    """
    yaml = ruamel.yaml.YAML()
    ruamel_data = yaml.load(file_text)

    if file_type in ('tasks', 'handlers'):
        ruamel_tasks = ruamel_data
        pyyaml_tasks = pyyaml_data
    elif file_type == 'playbook':
        try:
            ruamel_tasks = []
            pyyaml_tasks = []
            for ruamel_play, pyyaml_play in zip(ruamel_data, pyyaml_data):
                ruamel_tasks.extend(ruamel_play.get('tasks'))
                pyyaml_tasks.extend(pyyaml_play.get('tasks'))
        except (AttributeError, TypeError):
            return pyyaml_data
    elif file_type == 'meta':
        if not isinstance(pyyaml_data, list):
            return pyyaml_data
        ruamel_tasks = [ruamel_data]
        pyyaml_tasks = pyyaml_data
    else:
        return pyyaml_data

    if len(ruamel_tasks) != len(pyyaml_tasks):
        return pyyaml_data

    for ruamel_task, pyyaml_task in zip(ruamel_tasks, pyyaml_tasks):
        skipped_rules = _get_rule_skips_from_task(ruamel_task)
        if skipped_rules:
            pyyaml_task['skipped_rules'] = skipped_rules

    return pyyaml_data
def append_skipped_rules(pyyaml_data, file_text, file_type):
    """ Uses ruamel.yaml to parse comments then adds a
        skipped_rules list to the task (or meta yaml block)
    """
    yaml = ruamel.yaml.YAML()
    ruamel_data = yaml.load(file_text)

    if file_type in ('tasks', 'handlers'):
        ruamel_tasks = ruamel_data
        pyyaml_tasks = pyyaml_data
    elif file_type == 'playbook':
        try:
            ruamel_tasks = []
            pyyaml_tasks = []
            for ruamel_play, pyyaml_play in zip(ruamel_data, pyyaml_data):
                ruamel_tasks.extend(ruamel_play.get('tasks'))
                pyyaml_tasks.extend(pyyaml_play.get('tasks'))
        except (AttributeError, TypeError):
            return pyyaml_data
    elif file_type == 'meta':
        if not isinstance(pyyaml_data, list):
            return pyyaml_data
        ruamel_tasks = [ruamel_data]
        pyyaml_tasks = pyyaml_data
    else:
        return pyyaml_data

    if len(ruamel_tasks) != len(pyyaml_tasks):
        return pyyaml_data

    for ruamel_task, pyyaml_task in zip(ruamel_tasks, pyyaml_tasks):
        skipped_rules = _get_rule_skips_from_task(ruamel_task)
        if skipped_rules:
            pyyaml_task['skipped_rules'] = skipped_rules

    return pyyaml_data
Uses ruamel.yaml to parse comments then adds a
        skipped_rules list to the task (or meta yaml block)