Support the ability to ignore directories for ansible-lint job

For automation-tools repo, skip comac and comac-in-a-box directories

Change-Id: I1ea1e7b8ee84cd60f10962c67c6496a4912e7cd2
diff --git a/jjb/defaults.yaml b/jjb/defaults.yaml
index fbba5b5..57adfc6 100644
--- a/jjb/defaults.yaml
+++ b/jjb/defaults.yaml
@@ -178,3 +178,7 @@
     # Give the version of the JDK to use when building
     # Parameter is used with `update-java-alternatives --set <jdk-distribution>`
     jdk-distribution: 'java-11-amazon-corretto'
+
+    # skip directories
+    # Used to skip directories in supported tests
+    skip-dirs: ''
diff --git a/jjb/lint.yaml b/jjb/lint.yaml
index 70795d7..67059af 100644
--- a/jjb/lint.yaml
+++ b/jjb/lint.yaml
@@ -83,6 +83,9 @@
     concurrent: true
 
     builders:
+      - inject:
+          properties-content: |
+            SKIP_DIRS={skip-dirs}
       - shell: !include-raw-escape: shell/ansiblelint.sh
 
 
diff --git a/jjb/shell/ansiblelint.sh b/jjb/shell/ansiblelint.sh
index 930c09f..ebb5328 100755
--- a/jjb/shell/ansiblelint.sh
+++ b/jjb/shell/ansiblelint.sh
@@ -17,6 +17,7 @@
 # ansiblelint.sh - check all yaml files that they pass the ansible-lint tool
 
 set +e -u -o pipefail
+
 fail_ansible=0
 
 # verify that we have ansible-lint installed
@@ -27,16 +28,30 @@
 
 echo "=> Linting Ansible Code with $(ansible-lint --version)"
 
+# allow directories to be skipped
+# space separated directory list expected in SKIP_DIRS
+
+SKIP_DIRS=""
+SKIP_REGEX=""
+
+if [[ -n $SKIP_DIRS ]]; then
+  echo "=> Skipping files matching these directories: $SKIP_DIRS"
+  # prefix with ./ as find generates, swap spaces for pipes
+  SKIP_REGEX=$(echo $SKIP_DIRS | sed 's/[^ ]*/.\/&\//g' | sed 's/ /|/g')
+fi
+
 while IFS= read -r -d '' yf
 do
-  echo "==> CHECKING: ${yf}"
-  # Ignore line length limit (E204) as it can't (as of v4.0.1) be
-  # overridden with the skip_ansible_lint tag
-  ansible-lint -x 204 -p "${yf}"
-  rc=$?
-  if [[ $rc != 0 ]]; then
-    echo "==> LINTING FAIL: ${yf}"
-    fail_ansible=1
+  if [[ $yf =~ $SKIP_REGEX ]]; then
+    echo "==> SKIPPING: ${yf}"
+  else
+    echo "==> CHECKING: ${yf}"
+    ansible-lint -p "${yf}"
+    rc=$?
+    if [[ $rc != 0 ]]; then
+      echo "==> LINTING FAIL: ${yf}"
+      fail_ansible=1
+    fi
   fi
 done < <(find "${WORKSPACE}" \( -name "*.yml" -o -name "*.yaml" \) -print0)
 
diff --git a/jjb/verify/automation-tools.yaml b/jjb/verify/automation-tools.yaml
index cebc476..60b1c43 100644
--- a/jjb/verify/automation-tools.yaml
+++ b/jjb/verify/automation-tools.yaml
@@ -16,6 +16,7 @@
       - 'tag-collision-reject':
           dependency-jobs: 'verify_automation-tools_licensed'
       - 'verify-ansible-lint':
+          skip-dirs: "comac comac-in-a-box"
           dependency-jobs: 'verify_automation-tools_tag-collision'
       - 'verify-shellcheck':
           dependency-jobs: 'verify_automation-tools_ansible-lint'