From d1956bd9f7fbb2fcd4a6ee0c4daddecbfe2dac6b Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Wed, 28 Mar 2018 22:44:50 +0200 Subject: [PATCH] Fix ansible-lint job The 'linters' tox environment was not running on roles, it was only running on playbooks. This change adds a command to the linters environment to ensure all roles are linted. Since these weren't being linted, there were some problems with them. The first was a warning about usage of the shell module. Both of these usages seemed appropriate, so this patch adds a skip_ansible_lint tag to each task that was failing. The second is a warning "no action detected in task" for zuul modules. This is due to the fact that the linter cannot find the custom module. One option is to set the ANSIBLE_LIBRARY path to point to the zuul ansible library directory[1], but the linter virtualenv does not actually have zuul installed. Instead, we just disable the linter for the failing tasks. This also cleans up a comment in the tox file that was referring to a nonexistent zuul job. [1] https://github.com/willthames/ansible-review/issues/16 Change-Id: Ie49da9a09733b623bb25c5a4c8aa07eacacf4b33 --- roles/prepare-workspace/tasks/main.yaml | 3 +++ roles/stage-output/tasks/main.yaml | 4 ++++ roles/start-zuul-console/tasks/main.yaml | 3 +++ roles/upload-logs/tasks/main.yaml | 3 +++ tox.ini | 4 +++- 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/roles/prepare-workspace/tasks/main.yaml b/roles/prepare-workspace/tasks/main.yaml index 48fc29ac0..07161907e 100644 --- a/roles/prepare-workspace/tasks/main.yaml +++ b/roles/prepare-workspace/tasks/main.yaml @@ -1,6 +1,9 @@ # TODO(pabelanger): Handle cleanup on static nodes - name: Start zuul_console daemon. zuul_console: + tags: + # Avoid "no action detected in task" linter error + - skip_ansible_lint - name: Synchronize src repos to workspace directory. synchronize: diff --git a/roles/stage-output/tasks/main.yaml b/roles/stage-output/tasks/main.yaml index 38d806a31..5b6d2f043 100644 --- a/roles/stage-output/tasks/main.yaml +++ b/roles/stage-output/tasks/main.yaml @@ -90,6 +90,8 @@ shell: "mv {{ item.path }} {{ item.path | regex_replace(extensions_regex, '\\1_\\2.txt') }}" with_items: "{{ log_files_to_rename.files }}" chdir: "{{ stage_dir }}/logs" + tags: + - skip_ansible_lint # NOTE(andreaf) The ansible module does not support recursive archive, so # using gzip is the only option here. The good bit is that gzip itself is @@ -104,3 +106,5 @@ when: - stage_compress_logs - item.type == 'logs' + tags: + - skip_ansible_lint diff --git a/roles/start-zuul-console/tasks/main.yaml b/roles/start-zuul-console/tasks/main.yaml index 393a8f064..2fdcaf913 100644 --- a/roles/start-zuul-console/tasks/main.yaml +++ b/roles/start-zuul-console/tasks/main.yaml @@ -1,3 +1,6 @@ # TODO(pabelanger): Handle cleanup on static nodes - name: Start zuul_console daemon. zuul_console: + tags: + # Avoid "no action detected in task" linter error + - skip_ansible_lint diff --git a/roles/upload-logs/tasks/main.yaml b/roles/upload-logs/tasks/main.yaml index 661ce9aec..69e1cfae9 100644 --- a/roles/upload-logs/tasks/main.yaml +++ b/roles/upload-logs/tasks/main.yaml @@ -56,3 +56,6 @@ zuul: log_url: "{{ zuul_log_url }}/{{ zuul_log_path }}/" when: zuul_log_url is defined + tags: + # Avoid "no action detected in task" linter error + - skip_ansible_lint diff --git a/tox.ini b/tox.ini index 8b9e8bb8b..5c71936c5 100644 --- a/tox.ini +++ b/tox.ini @@ -25,7 +25,7 @@ commands = python setup.py build_sphinx passenv = # NOTE(pabelanger): if you'd like to run tox -elinters locally, you'll need # to export ANSIBLE_ROLES_PATH pointing to the currect repos. - # see infra-zuul-jobs-linters job for more information. + # see openstack-zuul-jobs-linters job for more information. ANSIBLE_ROLES_PATH whitelist_externals = bash commands = @@ -34,6 +34,8 @@ commands = # [ANSIBLE0012] Commands should not change things if nothing needs doing bash -c "find playbooks -type f -regex '.*.ya?ml' -print0 | \ xargs -t -n1 -0 ansible-lint -xANSIBLE0012" + bash -c 'find roles -maxdepth 1 -mindepth 1 -type d -printf "%p/\n" | \ + xargs -t -n1 ansible-lint -xANSIBLE0012' # Ansible Syntax Check bash -c "find playbooks -type f -regex '.*.ya?ml' -exec \ ansible-playbook --syntax-check -i {toxinidir}/tests/inventory \{\} + > /dev/null"