From f769c9d0f4d8d0752f6a65ed47a1ec95f06d85a3 Mon Sep 17 00:00:00 2001
From: Paul Belanger <pabelanger@redhat.com>
Date: Tue, 17 Oct 2017 12:51:21 -0400
Subject: [PATCH] Create openstack-zuul-jobs-linters jobs

This will be a cross repo linter jobs for openstack-zuul-jobs,
project-config and zuul-jobs.

Each repo will be able to run this job, which sets up all our projects
roles in the correct locations.

Depends-On: I59e5d41a9539671ee5aab9b9036379eb9101d021
Change-Id: I16186c929e7d0e6e34b35271559e555255a52b00
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
---
 test-requirements.txt |  3 ---
 tox.ini               | 12 ++++++++++--
 zuul.d/jobs.yaml      | 15 +++++++++++++++
 zuul.d/project.yaml   |  8 ++------
 4 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/test-requirements.txt b/test-requirements.txt
index dfe6062b..32d85882 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -8,6 +8,3 @@ ansible<2.4.0
 ansible-lint
 bashate>=0.2
 zuul-sphinx>=0.2.0
-
-# zuul-jobs is required to supply the ansible roles for ansible-lint
--e git://git.openstack.org/openstack-infra/zuul-jobs#egg=zuul-jobs
diff --git a/tox.ini b/tox.ini
index 01636e3c..1097ece3 100644
--- a/tox.ini
+++ b/tox.ini
@@ -22,11 +22,19 @@ commands = bindep test
 commands = python setup.py build_sphinx
 
 [testenv:linters]
-setenv =
-  ANSIBLE_ROLES_PATH = {toxinidir}/roles:{envdir}/src/zuul-jobs/roles
 whitelist_externals = bash
+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.
+  ANSIBLE_ROLES_PATH
 commands =
   flake8 {posargs}
+  # Ansible lint
+  # [ANSIBLE0012] Commands should not change things if nothing needs doing
+  bash -c "find playbooks -type d -name "legacy" -prune -o \
+    -type f -regex '.*.y[a]ml' -print0 | xargs -t -n1 -0 \
+    ansible-lint -xANSIBLE0012"
   # Ansible Syntax Check
   bash -c "cd playbooks; find . -type f -regex '.*.y[a]?ml' -exec \
     ansible-playbook --syntax-check -i {toxinidir}/tests/inventory \{\} + > /dev/null"
diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml
index 0765bdc4..12fa8110 100644
--- a/zuul.d/jobs.yaml
+++ b/zuul.d/jobs.yaml
@@ -770,3 +770,18 @@
     parent: legacy-base
     required-projects:
       - openstack/requirements
+
+- job:
+    name: openstack-zuul-jobs-linters
+    parent: tox
+    description: |
+      This job runs against project-config, openstack-zuul-jobs and zuul-jobs
+      so we can properly lint our ansible playbooks / roles
+    required-projects:
+      - openstack-infra/openstack-zuul-jobs
+      - openstack-infra/project-config
+      - openstack-infra/zuul-jobs
+    vars:
+      tox_envlist: linters
+      tox_environment:
+        ANSIBLE_ROLES_PATH: ~/src/git.openstack.org/openstack-infra/zuul-jobs/roles:~/src/git.openstack.org/openstack-infra/openstack-zuul-jobs/roles:~/src/git.openstack.org/openstack-infra/project-config/roles
diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml
index 9c6b5312..e4ffb737 100644
--- a/zuul.d/project.yaml
+++ b/zuul.d/project.yaml
@@ -17,9 +17,8 @@
         - multinode-integration-ubuntu-xenial
         - multinode-integration-opensuse423
         - build-openstack-sphinx-docs
-        - tox-linters:
-            required-projects:
-              - openstack-infra/zuul-jobs
+        - openstack-zuul-jobs-linters:
+            voting: false
     gate:
       jobs:
         - base-integration-centos-7
@@ -34,6 +33,3 @@
         - multinode-integration-ubuntu-xenial
         - multinode-integration-opensuse423
         - build-openstack-sphinx-docs
-        - tox-linters:
-            required-projects:
-              - openstack-infra/zuul-jobs