From 2850e2267a4cbe76918f3c783f56793ec91c14ea Mon Sep 17 00:00:00 2001 From: Al Bailey Date: Fri, 11 Oct 2019 09:21:28 -0500 Subject: [PATCH] Add in the ability to call ansible-lint from tox. The list of all ansible-lint error codes is documented here: https://docs.ansible.com/ansible-lint/rules/default_rules.html The failing ansible-lint checks are suppressed by the skip_list entry in .ansible-lint file. Those should be fixed in followup commits by an ansible expert. The tox target can be invoked locally by: tox -e ansible-lint The ansible-lint target is automatically included in the linters tox targer, which is already inoked by zuul. Story: 2004515 Task: 37144 Change-Id: I9a3e90aebdf6915f3a55b894bda2cd0919b073fd Signed-off-by: Al Bailey --- .ansible-lint | 28 ++++++++++++++++++++++++++++ test-requirements.txt | 3 ++- tox.ini | 8 ++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .ansible-lint diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 000000000..de5b854fd --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,28 @@ +# exclude_paths: + +parseable: true + +quiet: true + +# rulesdir: + +# All errors below should be cleaned up in ansible and removed from the skip_list +skip_list: + - '204' # [E204] Lines should be no longer than 160 chars + - '206' # [E206] Variables should have spaces before and after: {{ var_name } + - '301' # [E301] Commands should not change things if nothing needs doing + - '303' # [E303] systemctl used in place of systemd module + - '305' # [E305] Use shell only when shell functionality is required + - '306' # [E306] Shells that use pipes should set the pipefail option + - '501' # [E501] become_user requires become to work as expected + - '502' # [502] All tasks should be named + - '504' # [E504] Do not use 'local_action', use 'delegate_to: localhost' + - '601' # [E601] Don't compare to literal True/False + - '602' # [E602] Don't compare to empty string + - '701' # [E701] No 'galaxy_info' found + +# tags: + +use_default_rules: true + +verbosity: 1 diff --git a/test-requirements.txt b/test-requirements.txt index b891eae81..5324da3aa 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,5 @@ +ansible-lint bashate >= 0.2 +flake8 >= 2.5.4 # MIT PyYAML >= 3.1.0 yamllint >= 0.5.2 -flake8 >= 2.5.4 # MIT diff --git a/tox.ini b/tox.ini index 90ae01a79..ba2ec44ff 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,7 @@ deps = -r{toxinidir}/test-requirements.txt basepython = python3 whitelist_externals = bash commands = + {[testenv:ansible-lint]commands} bash -c "find {toxinidir} \ -not \( -type d -name .?\* -prune \) \ -type f \ @@ -28,6 +29,13 @@ commands = -o -name '*.yml' \ -print0 | xargs -0 yamllint" +[testenv:ansible-lint] +basepython = python3 +whitelist_externals = bash +# ansible-lint error checks are suppressed/skipped through the .ansible-lint file +commands = + bash -c "ls playbookconfig/src/playbooks/*.yml | xargs --no-run-if-empty ansible-lint" + [testenv:pep8] basepython = python3 usedevelop = False