From 681ff01f8b810dc3e9f63de8e5ee9b2101849309 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 12 Jul 2018 12:38:09 +0100 Subject: [PATCH] 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 --- .ansible-lint | 5 ++++ .pre-commit-config.yaml | 7 +++++ ci-scripts/ansible-lint.sh | 29 ------------------- doc/source/contributing.rst | 3 ++ ...k-out-general-config-8a02f40113e58dbc.yaml | 2 +- .../setup/supplemental/tasks/provision.yml | 2 ++ roles/libvirt/setup/undercloud/tasks/main.yml | 5 +++- test-requirements.txt | 4 +-- tox.ini | 4 ++- 9 files changed, 27 insertions(+), 34 deletions(-) create mode 100644 .ansible-lint create mode 100644 .pre-commit-config.yaml delete mode 100644 ci-scripts/ansible-lint.sh diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 000000000..2bb3ffb29 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,5 @@ +parseable: true +skip_list: + - ANSIBLE0006 + - ANSIBLE0012 + - ANSIBLE0016 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..e245a3bc5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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)$ diff --git a/ci-scripts/ansible-lint.sh b/ci-scripts/ansible-lint.sh deleted file mode 100644 index 8c4d610a7..000000000 --- a/ci-scripts/ansible-lint.sh +++ /dev/null @@ -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 - diff --git a/doc/source/contributing.rst b/doc/source/contributing.rst index 5eead6975..4169a08e5 100644 --- a/doc/source/contributing.rst +++ b/doc/source/contributing.rst @@ -24,6 +24,9 @@ If you wish to contribute, you'll want to get setup by following the documentation available at `How To Contribute `__. +Developers are encouraged to install `pre-commit `__ 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 `__ tool, then from the ``tripleo-quickstart`` repository run:: diff --git a/releasenotes/notes/break-out-general-config-8a02f40113e58dbc.yaml b/releasenotes/notes/break-out-general-config-8a02f40113e58dbc.yaml index 6ccb14b75..c2de7db71 100644 --- a/releasenotes/notes/break-out-general-config-8a02f40113e58dbc.yaml +++ b/releasenotes/notes/break-out-general-config-8a02f40113e58dbc.yaml @@ -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[_N[_N]...].yml Where N is the number of nodes of a certain , could be one of ctlr for controllers, comp for diff --git a/roles/libvirt/setup/supplemental/tasks/provision.yml b/roles/libvirt/setup/supplemental/tasks/provision.yml index c074fefc3..a661ccade 100644 --- a/roles/libvirt/setup/supplemental/tasks/provision.yml +++ b/roles/libvirt/setup/supplemental/tasks/provision.yml @@ -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 diff --git a/roles/libvirt/setup/undercloud/tasks/main.yml b/roles/libvirt/setup/undercloud/tasks/main.yml index a195ae438..7c63a67a3 100644 --- a/roles/libvirt/setup/undercloud/tasks/main.yml +++ b/roles/libvirt/setup/undercloud/tasks/main.yml @@ -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: diff --git a/test-requirements.txt b/test-requirements.txt index 7eec2ab08..640fe306c 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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 \ No newline at end of file +yamllint # GPLv3 +pre-commit # MIT \ No newline at end of file diff --git a/tox.ini b/tox.ini index 68bebaa90..f15bb8c9c 100644 --- a/tox.ini +++ b/tox.ini @@ -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