mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add yamllint for plugin docs and fix issues.
This commit is contained in:
parent
0b7932db30
commit
15b6837daf
13 changed files with 50 additions and 19 deletions
|
@ -19,7 +19,7 @@ DOCUMENTATION = '''
|
|||
- constructed
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
EXAMPLES = r'''
|
||||
# inventory.config file in YAML format
|
||||
plugin: constructed
|
||||
strict: False
|
||||
|
|
|
@ -28,8 +28,8 @@ DOCUMENTATION = """
|
|||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- debug
|
||||
msg: {{ lookup('chef_databag', 'name=data_bag_name item=data_bag_item') }}
|
||||
- debug:
|
||||
msg: "{{ lookup('chef_databag', 'name=data_bag_name item=data_bag_item') }}"
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
|
|
|
@ -31,7 +31,8 @@ EXAMPLES = """
|
|||
debug: msg="{{ lookup('config', 'DEFAULT_BECOME_USER')}}"
|
||||
|
||||
- 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
|
||||
find:
|
||||
|
|
|
@ -43,8 +43,8 @@ DOCUMENTATION = """
|
|||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- debug
|
||||
msg: {{ lookup('conjur_variable', '/path/to/secret') }}
|
||||
- debug:
|
||||
msg: "{{ lookup('conjur_variable', '/path/to/secret') }}"
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
|
|
|
@ -19,12 +19,6 @@ DOCUMENTATION = """
|
|||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
tasks:
|
||||
- name: show dictionary
|
||||
debug: msg="{{item.key}}: {{item.value}}"
|
||||
with_dict: {a: 1, b: 2, c: 3}
|
||||
|
||||
# with predefined vars
|
||||
vars:
|
||||
users:
|
||||
alice:
|
||||
|
@ -34,10 +28,16 @@ vars:
|
|||
name: Bob Bananarama
|
||||
telephone: 987-654-3210
|
||||
tasks:
|
||||
# with predefined vars
|
||||
- name: Print phone records
|
||||
debug:
|
||||
msg: "User {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})"
|
||||
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 = """
|
||||
|
|
|
@ -40,7 +40,8 @@ EXAMPLES = """
|
|||
- testuser2
|
||||
|
||||
- name: "loop through list from a variable"
|
||||
debug: msg="An item: {{item}}"
|
||||
debug:
|
||||
msg: "An item: {{item}}"
|
||||
with_items: "{{ somelist }}"
|
||||
|
||||
- name: more complex items to add several users
|
||||
|
|
|
@ -27,7 +27,7 @@ EXAMPLES = """
|
|||
with_nested:
|
||||
- [ 'alice', 'bob' ]
|
||||
- [ '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
|
||||
mysql_user:
|
||||
|
|
|
@ -69,7 +69,7 @@ EXAMPLES = """
|
|||
|
||||
- name: get a host record
|
||||
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
|
||||
set_fact:
|
||||
|
|
|
@ -40,7 +40,7 @@ EXAMPLES = """
|
|||
variablename: hello
|
||||
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') }}"
|
||||
|
||||
- name: alternate way to find some 'prefixed vars' in loop
|
||||
|
|
|
@ -34,6 +34,10 @@ class YamllintTest(SanitySingleVersion):
|
|||
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] == '.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
|
||||
os.path.basename(i.path) != '__init__.py' and
|
||||
i.path.startswith('lib/ansible/modules/')],
|
||||
|
|
19
test/sanity/yamllint/config/plugins.yml
Normal file
19
test/sanity/yamllint/config/plugins.yml
Normal file
|
@ -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')
|
||||
module_conf = YamlLintConfig(file='test/sanity/yamllint/config/modules.yml')
|
||||
plugin_conf = YamlLintConfig(file='test/sanity/yamllint/config/plugins.yml')
|
||||
|
||||
for path in paths:
|
||||
extension = os.path.splitext(path)[1]
|
||||
|
@ -50,7 +51,12 @@ class YamlChecker(object):
|
|||
if extension in ('.yml', '.yaml'):
|
||||
self.check_yaml(yaml_conf, path, contents)
|
||||
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:
|
||||
raise Exception('unsupported extension: %s' % extension)
|
||||
|
||||
|
@ -137,7 +143,7 @@ class YamlChecker(object):
|
|||
if not module_ast:
|
||||
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:
|
||||
if isinstance(body_statement, ast.Assign):
|
||||
check_assignment(body_statement, module_doc_types)
|
||||
|
|
Loading…
Reference in a new issue