File: MetaMainHasInfoRule.py

package info (click to toggle)
ansible-lint 4.1.0%2Bdfsg.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,096 kB
  • sloc: python: 3,373; sh: 4; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,378 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright (c) 2016, Will Thames and contributors
# Copyright (c) 2018, Ansible Project

from ansiblelint import AnsibleLintRule


class MetaMainHasInfoRule(AnsibleLintRule):
    id = '701'
    shortdesc = 'meta/main.yml should contain relevant info'
    info = [
        'author',
        'description',
        'license',
        'min_ansible_version',
        'platforms',
    ]
    description = (
        'meta/main.yml should contain: ``{}``'.format(', '.join(info))
    )
    severity = 'HIGH'
    tags = ['metadata']
    version_added = 'v4.0.0'

    def matchplay(self, file, data):
        if file['type'] != 'meta':
            return False

        galaxy_info = data.get('galaxy_info', None)
        if not galaxy_info:
            return [({'meta/main.yml': data},
                    "No 'galaxy_info' found")]

        results = []
        for info in self.info:
            if not galaxy_info.get(info, None):
                results.append(({'meta/main.yml': data},
                                'Role info should contain %s' % info))

        platforms = galaxy_info.get('platforms', None)
        if platforms:
            for platform in platforms:
                if not platform.get('name', None):
                    results.append(({'meta/main.yml': data},
                                    'Platform should contain name'))

        return results