Skip to content

Commit

Permalink
Add yamllint for plugin docs and fix issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclay committed May 23, 2018
1 parent 0b7932d commit 15b6837
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/ansible/plugins/inventory/constructed.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- constructed
'''

EXAMPLES = '''
EXAMPLES = r'''
# inventory.config file in YAML format
plugin: constructed
strict: False
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/plugins/lookup/chef_databag.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"""

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 = """
Expand Down
3 changes: 2 additions & 1 deletion lib/ansible/plugins/lookup/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
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:
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/plugins/lookup/conjur_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"""

EXAMPLES = """
- debug
msg: {{ lookup('conjur_variable', '/path/to/secret') }}
- debug:
msg: "{{ lookup('conjur_variable', '/path/to/secret') }}"
"""

RETURN = """
Expand Down
12 changes: 6 additions & 6 deletions lib/ansible/plugins/lookup/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
"""

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:
Expand All @@ -34,10 +28,16 @@
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 = """
Expand Down
3 changes: 2 additions & 1 deletion lib/ansible/plugins/lookup/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
- 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
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/plugins/lookup/nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
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:
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/plugins/lookup/nios.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
- 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:
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/plugins/lookup/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
priv: "{{ client }}_{{ tier }}_{{ role }}.*:ALL"
- 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
mysql_user:
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/plugins/lookup/vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
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
Expand Down
4 changes: 4 additions & 0 deletions test/runner/lib/sanity/yamllint.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def test(self, args, targets):
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/')],
Expand Down
19 changes: 19 additions & 0 deletions test/sanity/yamllint/config/plugins.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 8 additions & 2 deletions test/sanity/yamllint/yamllinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def check(self, paths):
"""
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]
Expand All @@ -50,7 +51,12 @@ def check(self, paths):
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)

Expand Down Expand Up @@ -137,7 +143,7 @@ def check_assignment(statement, doc_types=None):
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)
Expand Down

0 comments on commit 15b6837

Please sign in to comment.