From a08424387ed0c77504b5516c63468369e6bfebfc Mon Sep 17 00:00:00 2001
From: Paul Belanger <pabelanger@redhat.com>
Date: Thu, 12 Jan 2017 15:32:46 -0500
Subject: [PATCH] Run ansible-lint on playbooks

This fixes the issues we have with our rename_repos.yaml file. We are
also skipping additional failures for now, which will be cleaned up in
a follow up patch.

Change-Id: I726535e195a292e3f2d457f0ed039d01bb96c66b
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
---
 playbooks/rename_repos.yaml | 12 ++++++------
 test-requirements.txt       |  1 +
 tox.ini                     |  4 ++++
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/playbooks/rename_repos.yaml b/playbooks/rename_repos.yaml
index 20b7f35471..ac9e06d259 100644
--- a/playbooks/rename_repos.yaml
+++ b/playbooks/rename_repos.yaml
@@ -6,13 +6,13 @@
   - shell: invoke-rc.d gerrit stop
   - include_vars: "{{ repolist }}"
   - shell: echo 'update account_project_watches set project_name = "{{ item.new }}" where project_name = "{{ item.old }}";' | mysql reviewdb
-    with_items: {{ repos }}
+    with_items: "{{ repos }}"
   - shell: echo 'update changes set dest_project_name = "{{ item.new }}", created_on = created_on where dest_project_name = "{{ item.old }}";' | mysql reviewdb
-    with_items: {{ repos }}
+    with_items: "{{ repos }}"
   - shell: mv {{ item[0] }}{{ item[1].old }}.git {{ item[0] }}{{ item[1].new }}.git
     with_nested:
     - [ '~gerrit2/review_site/git/', '/opt/lib/git/' ]
-    - {{ repos }}
+    - "{{ repos }}"
 - hosts: 'git0*'
   gather_facts: False
   tasks:
@@ -20,14 +20,14 @@
   - shell: mv {{ item[0] }}{{ item[1].old }}.git {{ item[0] }}{{ item[1].new }}.git
     with_nested:
     - [ '/var/lib/git/' ]
-    - {{ repos }}
+    - "{{ repos }}"
 - hosts: storyboard.openstack.org
   gather_facts: False
   remote_user: root
   tasks:
   - include_vars: "{{ repolist }}"
   - shell: echo 'update projects set name="{{ item.new }}" where name="{{ item.old }}";' | mysql --defaults-file=/root/.storyboard_db.cnf storyboard
-    with_items: {{ repos }}
+    with_items: "{{ repos }}"
 - hosts: review.openstack.org
   gather_facts: False
   remote_user: root
@@ -58,4 +58,4 @@
   tasks:
   - include_vars: "{{ repolist }}"
   - shell: 'rm -rf ~jenkins/workspace/*{{ item.old | basename }}*'
-    with_items: {{ repos }}
+    with_items: "{{ repos }}"
diff --git a/test-requirements.txt b/test-requirements.txt
index cbe1615b7b..57a07b4b55 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -3,3 +3,4 @@ Sphinx>=1.1.2,<1.2
 oslosphinx
 bashate>=0.2
 PyYAML
+ansible-lint
diff --git a/tox.ini b/tox.ini
index 5c5e284c5e..4c24aa0132 100644
--- a/tox.ini
+++ b/tox.ini
@@ -9,11 +9,15 @@ install_command = pip install {opts} {packages}
 deps = -r{toxinidir}/test-requirements.txt
 
 [testenv:linters]
+whitelist_externals = bash
 commands =
   flake8
   {toxinidir}/tools/run-bashate.sh
   python {toxinidir}/tools/sorted_modules_env.py {toxinidir}/modules.env
   python {toxinidir}/tools/irc_checks.py
+  # Ansible Lint Check
+  bash -c "find playbooks -type f -regex '.*.y[a]?ml' -print0 | xargs -t -n1 -0 \
+    ansible-lint -x ANSIBLE0004,ANSIBLE0006,ANSIBLE0007,ANSIBLE0011,ANSIBLE0012,ANSIBLE0013,ANSIBLE0015"
 
 [testenv:venv]
 commands = {posargs}