Add yamllint for plugin docs and fix issues.

pull/33660/head
Matt Clay 7 years ago
parent 0b7932db30
commit 15b6837daf

@ -19,7 +19,7 @@ DOCUMENTATION = '''
- constructed - constructed
''' '''
EXAMPLES = ''' EXAMPLES = r'''
# inventory.config file in YAML format # inventory.config file in YAML format
plugin: constructed plugin: constructed
strict: False strict: False

@ -28,8 +28,8 @@ DOCUMENTATION = """
""" """
EXAMPLES = """ EXAMPLES = """
- debug - debug:
msg: {{ lookup('chef_databag', 'name=data_bag_name item=data_bag_item') }} msg: "{{ lookup('chef_databag', 'name=data_bag_name item=data_bag_item') }}"
""" """
RETURN = """ RETURN = """

@ -31,7 +31,8 @@ EXAMPLES = """
debug: msg="{{ lookup('config', 'DEFAULT_BECOME_USER')}}" debug: msg="{{ lookup('config', 'DEFAULT_BECOME_USER')}}"
- name: print out role paths - name: print out role paths
debug: msg="These are the configured role paths: {{lookup('config', 'DEFAULT_ROLES_PATH')}}" debug:
msg: "These are the configured role paths: {{lookup('config', 'DEFAULT_ROLES_PATH')}}"
- name: find retry files, skip if missing that key - name: find retry files, skip if missing that key
find: find:

@ -43,8 +43,8 @@ DOCUMENTATION = """
""" """
EXAMPLES = """ EXAMPLES = """
- debug - debug:
msg: {{ lookup('conjur_variable', '/path/to/secret') }} msg: "{{ lookup('conjur_variable', '/path/to/secret') }}"
""" """
RETURN = """ RETURN = """

@ -19,12 +19,6 @@ DOCUMENTATION = """
""" """
EXAMPLES = """ EXAMPLES = """
tasks:
- name: show dictionary
debug: msg="{{item.key}}: {{item.value}}"
with_dict: {a: 1, b: 2, c: 3}
# with predefined vars
vars: vars:
users: users:
alice: alice:
@ -34,10 +28,16 @@ vars:
name: Bob Bananarama name: Bob Bananarama
telephone: 987-654-3210 telephone: 987-654-3210
tasks: tasks:
# with predefined vars
- name: Print phone records - name: Print phone records
debug: debug:
msg: "User {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})" msg: "User {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})"
loop: "{{ lookup('dict', users) }}" loop: "{{ lookup('dict', users) }}"
# with inline dictionary
- name: show dictionary
debug:
msg: "{{item.key}}: {{item.value}}"
with_dict: {a: 1, b: 2, c: 3}
""" """
RETURN = """ RETURN = """

@ -40,7 +40,8 @@ EXAMPLES = """
- testuser2 - testuser2
- name: "loop through list from a variable" - name: "loop through list from a variable"
debug: msg="An item: {{item}}" debug:
msg: "An item: {{item}}"
with_items: "{{ somelist }}" with_items: "{{ somelist }}"
- name: more complex items to add several users - name: more complex items to add several users

@ -27,7 +27,7 @@ EXAMPLES = """
with_nested: with_nested:
- [ 'alice', 'bob' ] - [ 'alice', 'bob' ]
- [ 'clientdb', 'employeedb', 'providerdb' ] - [ 'clientdb', 'employeedb', 'providerdb' ]
As with the case of 'with_items' above, you can use previously defined variables.: # As with the case of 'with_items' above, you can use previously defined variables.:
- name: here, 'users' contains the above list of employees - name: here, 'users' contains the above list of employees
mysql_user: mysql_user:

@ -69,7 +69,7 @@ EXAMPLES = """
- name: get a host record - name: get a host record
set_fact: set_fact:
host: "{{ lookup('nios', 'record:host', filter={'name': 'hostname.ansible.com'}) }} host: "{{ lookup('nios', 'record:host', filter={'name': 'hostname.ansible.com'}) }}"
- name: get the authoritative zone from a non default dns view - name: get the authoritative zone from a non default dns view
set_fact: set_fact:

@ -68,7 +68,7 @@ EXAMPLES = """
priv: "{{ client }}_{{ tier }}_{{ role }}.*:ALL" priv: "{{ client }}_{{ tier }}_{{ role }}.*:ALL"
- name: create a mysql user with a random password using only ascii letters - name: create a mysql user with a random password using only ascii letters
mysql_user: name={{ client }} password="{{ lookup('password', '/tmp/passwordfile chars=ascii_letters') }}" priv='{{ client }}_{{ tier }}_{{ role }}.*:ALL' mysql_user: name={{ client }} password="{{ lookup('password', '/tmp/passwordfile chars=ascii_letters') }}" priv='{{ client }}_{{ tier }}_{{ role }}.*:ALL'
- name: create a mysql user with a random password using only digits - name: create a mysql user with a random password using only digits
mysql_user: mysql_user:

@ -40,7 +40,7 @@ EXAMPLES = """
variablename: hello variablename: hello
myvar: notename myvar: notename
- name: find several related variables: - name: find several related variables
debug: msg="{{ lookup('vars', 'ansible_play_hosts', 'ansible_play_batch', 'ansible_play_hosts_all') }}" debug: msg="{{ lookup('vars', 'ansible_play_hosts', 'ansible_play_batch', 'ansible_play_hosts_all') }}"
- name: alternate way to find some 'prefixed vars' in loop - name: alternate way to find some 'prefixed vars' in loop

@ -34,6 +34,10 @@ class YamllintTest(SanitySingleVersion):
paths = [ paths = [
[i.path for i in targets.include if os.path.splitext(i.path)[1] in ('.yml', '.yaml')], [i.path for i in targets.include if os.path.splitext(i.path)[1] in ('.yml', '.yaml')],
[i.path for i in targets.include if os.path.splitext(i.path)[1] == '.py' and
os.path.basename(i.path) != '__init__.py' and
i.path.startswith('lib/ansible/plugins/')],
[i.path for i in targets.include if os.path.splitext(i.path)[1] == '.py' and [i.path for i in targets.include if os.path.splitext(i.path)[1] == '.py' and
os.path.basename(i.path) != '__init__.py' and os.path.basename(i.path) != '__init__.py' and
i.path.startswith('lib/ansible/modules/')], i.path.startswith('lib/ansible/modules/')],

@ -0,0 +1,19 @@
extends: default
rules:
braces: disable
brackets: disable
colons: disable
commas: disable
comments: disable
comments-indentation: disable
document-start: disable
empty-lines: disable
hyphens: disable
indentation: disable
key-duplicates: disable
line-length: disable
new-line-at-end-of-file: disable
new-lines: {type: unix}
trailing-spaces: disable
truthy: disable

@ -40,6 +40,7 @@ class YamlChecker(object):
""" """
yaml_conf = YamlLintConfig(file='test/sanity/yamllint/config/default.yml') yaml_conf = YamlLintConfig(file='test/sanity/yamllint/config/default.yml')
module_conf = YamlLintConfig(file='test/sanity/yamllint/config/modules.yml') module_conf = YamlLintConfig(file='test/sanity/yamllint/config/modules.yml')
plugin_conf = YamlLintConfig(file='test/sanity/yamllint/config/plugins.yml')
for path in paths: for path in paths:
extension = os.path.splitext(path)[1] extension = os.path.splitext(path)[1]
@ -50,7 +51,12 @@ class YamlChecker(object):
if extension in ('.yml', '.yaml'): if extension in ('.yml', '.yaml'):
self.check_yaml(yaml_conf, path, contents) self.check_yaml(yaml_conf, path, contents)
elif extension == '.py': elif extension == '.py':
self.check_module(module_conf, path, contents) if path.startswith('lib/ansible/plugins/'):
conf = plugin_conf
else:
conf = module_conf
self.check_module(conf, path, contents)
else: else:
raise Exception('unsupported extension: %s' % extension) raise Exception('unsupported extension: %s' % extension)
@ -137,7 +143,7 @@ class YamlChecker(object):
if not module_ast: if not module_ast:
return {} return {}
if path.startswith('lib/ansible/modules/'): if path.startswith('lib/ansible/modules/') or path.startswith('lib/ansible/plugins/'):
for body_statement in module_ast.body: for body_statement in module_ast.body:
if isinstance(body_statement, ast.Assign): if isinstance(body_statement, ast.Assign):
check_assignment(body_statement, module_doc_types) check_assignment(body_statement, module_doc_types)

Loading…
Cancel
Save