From 34fee74bdc6fb9d1d757c0194786e3b01b970ce4 Mon Sep 17 00:00:00 2001
From: Chris Croome <chris@webarchitects.co.uk>
Date: Sun, 30 Apr 2023 10:14:13 +0100
Subject: [PATCH] Verify tasks in seperate file

---
 meta/argument_specs.yml |  4 ++++
 tasks/main.yml          | 21 +++++++--------------
 tasks/verify.yml        | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 14 deletions(-)
 create mode 100644 tasks/verify.yml

diff --git a/meta/argument_specs.yml b/meta/argument_specs.yml
index d58b0fd..548e027 100644
--- a/meta/argument_specs.yml
+++ b/meta/argument_specs.yml
@@ -258,6 +258,10 @@ argument_specs:
         elements: str
         required: false
         description: A generated list of PHP versions which should be present.
+      php_verify:
+        type: bool
+        required: false
+        description: Varify all variables starting with php_ using the argument spec.
       php_versions:
         type: list
         elements: dict
diff --git a/tasks/main.yml b/tasks/main.yml
index ff354f5..e4f441f 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -11,20 +11,13 @@
 - name: PHP
   block:
 
-    - name: Debug the hostvars variable names that start with php_
-      ansible.builtin.debug:
-        var: phpvarnames
-        verbosity: "{% if ansible_check_mode | bool %}3{% else %}4{% endif %}"
-
-    - name: Debug the hostvars variable names that start with php_
-      ansible.builtin.debug:
-        var: phphostvars
-        verbosity: "{% if ansible_check_mode | bool %}3{% else %}4{% endif %}"
-
-    - name: Check php_ variables using meta/argument_specs.yml
-      ansible.builtin.validate_argument_spec:
-        argument_spec: "{{ (lookup('ansible.builtin.file', 'meta/argument_specs.yml') | from_yaml )['argument_specs']['main']['options'] }}"
-        provided_arguments: "{{ phphostvars }}"
+    - name: Include PHP verify variables tasks
+      ansible.builtin.include_tasks: verify.yml
+      when:
+        - php_verify is defined
+        - php_verify | bool
+      tags:
+        - php_verify
 
     - name: Include apt role local fact tasks
       ansible.builtin.include_role:
diff --git a/tasks/verify.yml b/tasks/verify.yml
new file mode 100644
index 0000000..99212a3
--- /dev/null
+++ b/tasks/verify.yml
@@ -0,0 +1,35 @@
+# Copyright 2019-2023 Chris Croome
+#
+# This file is part of the Webarchitects PHP Ansible role.
+#
+# The Webarchitects PHP Ansible role is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+#
+# The Webarchitects PHP Ansible role is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with the Webarchitects PHP Ansible role. If not, see <https://www.gnu.org/licenses/>.
+---
+- name: Verify PHP variables
+  block:
+
+    - name: Debug the hostvars variable names that start with php_
+      ansible.builtin.debug:
+        var: phpvarnames
+        verbosity: "{% if ansible_check_mode | bool %}3{% else %}4{% endif %}"
+
+    - name: Debug the hostvars variable names that start with php_
+      ansible.builtin.debug:
+        var: phphostvars
+        verbosity: "{% if ansible_check_mode | bool %}3{% else %}4{% endif %}"
+
+    - name: Check php_ variables using meta/argument_specs.yml
+      ansible.builtin.validate_argument_spec:
+        argument_spec: "{{ (lookup('ansible.builtin.file', 'meta/argument_specs.yml') | from_yaml )['argument_specs']['main']['options'] }}"
+        provided_arguments: "{{ phphostvars }}"
+
+  when:
+    - php_verify is defined
+    - php_verify | bool
+  tags:
+    - php
+    - pgp_verify
+...
-- 
GitLab