From 72818470959b54371db5c5d7657d13000ea795ae Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Fri, 17 Nov 2017 10:34:28 +0000
Subject: [PATCH] Add a tox environment ansible-syntax for checking ansible
 syntax

Run this environment in TravisCI.
---
 .travis.yml |  2 ++
 tox.ini     | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index d603cabcb..33eceb2b3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -22,6 +22,8 @@ env:
     - TOX_ENV=docs
     # Run python2.7 unit tests.
     - TOX_ENV=py27
+    # Run ansible syntax checks.
+    - TOX_ENV=ansible-syntax
 
 install:
   # Install a virtualenv for tox.
diff --git a/tox.ini b/tox.ini
index 14b4e7c97..68270674a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -37,6 +37,26 @@ commands = oslo_debug_helper {posargs}
 [testenv:alint]
 commands = ansible-lint ansible/*.yaml
 
+[testenv:ansible-syntax]
+commands =
+    # Install ansible role dependencies from Galaxy.
+    ansible-galaxy install \
+        -r {toxinidir}/requirements.yml \
+        -p {toxinidir}/ansible/roles
+    # Perform an Ansible syntax check. Skip some playbooks which require extra
+    # variables to be defined.
+    bash -c \
+        "ansible-playbook \
+        --connection=local \
+        --syntax-check \
+        --list-tasks \
+        $(find {toxinidir}/ansible \
+            -maxdepth 1 \
+            -name '*.yml' \
+            -not -name idrac-bootstrap-one.yml \
+            -not -name idrac-bootstrap.yml) \
+        {posargs}"
+
 [flake8]
 # E123, E125 skipped as they are invalid PEP-8.