diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 000000000..aca43b872 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,18 @@ +exclude_paths: + - roles/validate-ui/.travis.yml +parseable: true +rulesdir: + - ./ci-scripts/ansible_rules/ +quiet: false +skip_list: + - ANSIBLE0006 # Using command rather than module we have a few use cases + # where we need to use curl and rsync + - ANSIBLE0007 # Using command rather than an argument to e.g file + # we have a lot of 'rm' command and we should use file module instead + - ANSIBLE0010 # Package installs should not use latest. + # Sometimes we need to update some packages. + - ANSIBLE0012 # Commands should not change things if nothing needs doing + - ANSIBLE0013 # Use Shell only when shell functionality is required + - ANSIBLE0016 # Tasks that run when changed should likely be handlers + # this requires refactoring roles, skipping for now +verbosity: 1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1a7c12d65..46cd928f9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v1.4.0 + rev: v2.0.0 hooks: - id: trailing-whitespace - id: mixed-line-ending @@ -20,7 +20,13 @@ repos: - id: yamllint files: \.(yaml|yml)$ types: [file, yaml] - entry: yamllint --strict + entry: yamllint --strict -f parsable + - repo: https://github.com/ansible/ansible-lint + rev: v3.5.1 + hooks: + - id: ansible-lint + files: \.(yaml|yml)$ + entry: ansible-lint --force-color -v - repo: https://github.com/openstack-dev/bashate.git rev: 0.6.0 hooks: diff --git a/ci-scripts/ansible-lint.sh b/ci-scripts/ansible-lint.sh deleted file mode 100755 index eccf581d3..000000000 --- a/ci-scripts/ansible-lint.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -# ANSIBLE0006: Using command rather than module -# we have a few use cases where we need to use curl and rsync -# ANSIBLE0007: Using command rather than an argument to e.g file -# we have a lot of 'rm' command and we should use file module instead -# ANSIBLE0010: Package installs should not use latest. -# Sometimes we need to update some packages. -# ANSIBLE0012: Commands should not change things if nothing needs doing -# ANSIBLE0013: Use Shell only when shell functionality is required -# ANSIBLE0016: Tasks that run when changed should likely be handlers -# this requires refactoring roles, skipping for now -SKIPLIST="ANSIBLE0006,ANSIBLE0007,ANSIBLE0010,ANSIBLE0012,ANSIBLE0013,ANSIBLE0016" - -# 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 -p -x $SKIPLIST -R -r ../ci-scripts/ansible_rules $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 -p -x $SKIPLIST -R -r ./ci-scripts/ansible_rules $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/test-requirements.txt b/test-requirements.txt index b4da7ee52..3370341c8 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,7 +1,6 @@ openstackdocstheme>=1.11.0 # Apache-2.0 pre-commit>=1.10 # MIT License -ansible-lint>=3.5.0 sphinx>=1.6.2 # BSD reno>=1.8.0 # Apache-2.0 jinja2 diff --git a/tox.ini b/tox.ini index d5f2115b7..51450f942 100644 --- a/tox.ini +++ b/tox.ini @@ -22,6 +22,7 @@ commands = bindep test commands = python setup.py build_sphinx [testenv:bashate] +envdir = {toxworkdir}/linters commands = python -m pre_commit run bashate --all-files @@ -31,9 +32,9 @@ commands = python -m pre_commit run flake8 --all-files [testenv:ansible-lint] -basepython=python2 +envdir = {toxworkdir}/linters commands = - bash ci-scripts/ansible-lint.sh + python -m pre_commit run ansible-lint -a [testenv:releasenotes] whitelist_externals = bash @@ -45,7 +46,6 @@ commands = python -m pre_commit run --source HEAD^ --origin HEAD # in the future we may want to check entire repository: # python -m pre_commit run yamllint --all-files - {[testenv:ansible-lint]commands} {[testenv:validate-jinja]commands} [testenv:venv]