enable ansible-lint as pre-commit hook

Enable auto linting on commit, for developers
that have pre-commit installed (pip install pre-commit)

Execution is extreamly fast (1-2s) due to caching and
because on commit only modified files are checked.

ci-scripts/ansible-lint.sh is now obsolete and removed,
as the same functionality is done via pre-commit.

Partial-Bug: #1786286
Change-Id: I6854145c71fd817d940c4b49b60b0853b2280cf0
This commit is contained in:
Sorin Sbarnea 2018-07-12 12:38:09 +01:00
parent 4e9954252e
commit 681ff01f8b
9 changed files with 27 additions and 34 deletions

5
.ansible-lint Normal file
View File

@ -0,0 +1,5 @@
parseable: true
skip_list:
- ANSIBLE0006
- ANSIBLE0012
- ANSIBLE0016

7
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,7 @@
repos:
- repo: https://github.com/willthames/ansible-lint.git
rev: v3.5.1
hooks:
- id: ansible-lint
entry: env ANSIBLE_LIBRARY=./library ansible-lint
files: \.(yaml|yml)$

View File

@ -1,29 +0,0 @@
#!/bin/bash
# ANSIBLE0006: Using command rather than module
# we have a few use cases where we need to use curl and rsync
# ANSIBLE0016: Tasks that run when changed should likely be handlers
# this requires refactoring roles, skipping for now
# ANSIBLE0012: Commands should not change things if nothing needs doing
# this requires refactoring roles, skipping for now
SKIPLIST="ANSIBLE0006,ANSIBLE0016,ANSIBLE0012"
# lint the playbooks separately to avoid linting the roles multiple times
pushd playbooks
for playbook in `find . -type f -regex '.*\.y[a]?ml'`; do
ansible-lint -vvv -x $SKIPLIST $playbook || lint_error=1
done
popd
# lint all the possible roles
# Due to https://github.com/willthames/ansible-lint/issues/210, the roles
# directories need to contain a trailing slash at the end of the path.
for rolesdir in `find ./roles -maxdepth 1 -type d`; do
ansible-lint -vvv -x $SKIPLIST $rolesdir/ || lint_error=1
done
# exit with 1 if we had a least an error or warning.
if [[ -n "$lint_error" ]]; then
exit 1;
fi

View File

@ -24,6 +24,9 @@ If you wish to contribute, you'll want to get setup by following the
documentation available at `How To
Contribute <https://wiki.openstack.org/wiki/How_To_Contribute>`__.
Developers are encouraged to install `pre-commit <https://pre-commit.com/#install>`__ in order
to auto-perform a minimal set of checks on commit.
Once you've cloned the repository using your account, install the
`git-review <https://docs.openstack.org/infra/manual/developers.html#installing-git-review>`__
tool, then from the ``tripleo-quickstart`` repository run::

View File

@ -9,7 +9,7 @@ features:
the overcloud nodes configuration, and all that involves
their set up, should be put into nodes configuration
files.
The nodes file should follow the scheme
The nodes file should follow the scheme
N<type>[_N<type>[_N<type>]...].yml
Where N is the number of nodes of a certain <type>,
<type> could be one of ctlr for controllers, comp for

View File

@ -78,6 +78,8 @@
- name: Provision script execution
shell: >
'bash ~/supplemental_node_provisioner.sh'
tags:
- skip_ansible_lint
# Start the supplemental node virtual machine.
- name: Start supplemental node vm

View File

@ -418,7 +418,8 @@
# In the upcoming release of ansible 2.4 this should be moved to
# iptables_raw
# - name: ensure the required tcp ports are open on the virthost
- iptables:
- name: configure iptables
iptables:
table: filter
chain: INPUT
action: insert
@ -452,6 +453,8 @@
- name: reload the systemctl daemon after file update
shell: systemctl daemon-reload
become: true
tags:
- skip_ansible_lint
- name: Enable ssh tunnel service
service:

View File

@ -2,8 +2,8 @@ openstackdocstheme>=1.11.0 # Apache-2.0
hacking<0.11,>=0.10
bashate>=0.2 # Apache-2.0
ansible-lint
docutils>=0.11
sphinx>=1.6.2 # BSD
reno>=1.8.0 # Apache-2.0
yamllint # GPLv3
yamllint # GPLv3
pre-commit # MIT

View File

@ -57,8 +57,10 @@ commands =
[testenv:ansible-lint]
basepython=python2
setenv =
ANSIBLE_LIBRARY=./library
commands =
bash ci-scripts/ansible-lint.sh
python -m pre_commit run --all-files
[testenv:linters]
basepython = python3