From 206736150add7ed6066b02f7477238f904875305 Mon Sep 17 00:00:00 2001
From: Chris Croome <chris@webarchitects.co.uk>
Date: Wed, 6 Sep 2023 21:20:48 +0100
Subject: [PATCH] Test install using GitLab CI in system container

---
 .gitlab-ci.yml                    | 47 +++++++++++++++++++++++++------
 molecule/default/converge.yml     | 38 +++++++++++++++++++++++++
 molecule/default/molecule.yml     | 14 ++++-----
 molecule/default/requirements.yml | 15 ++++++++++
 molecule/default/verify.yml       | 31 ++++++++++++++++++++
 5 files changed, 128 insertions(+), 17 deletions(-)
 create mode 100644 molecule/default/converge.yml
 create mode 100644 molecule/default/requirements.yml
 create mode 100644 molecule/default/verify.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0302f60..24465bc 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,17 +8,48 @@
 #
 # You should have received a copy of the GNU General Public License along with the Webarchitects Apache Ansible role. If not, see <https://www.gnu.org/licenses/>.
 ---
-image: registry.git.coop/webarch/containers/images/ansible:0.23.0
 variables:
-  PY_COLORS: "1"
+  ANSIBLE_CALLBACK_RESULT_FORMAT: "yaml"
+  ANSIBLE_DISPLAY_SKIPPED_HOSTS: "0"
   ANSIBLE_FORCE_COLOR: "1"
+  ANSIBLE_REMOTE_TMP: "/tmp"
+  ANSIBLE_SHELL_ALLOW_WORLD_READABLE_TEMP: "1"
+  MOLECULE_VERBOSITY: "0"
+  PY_COLORS: "1"
 before_script:
-  - chmod 700 $(pwd)
+  - whoami
+  - pwd
+  - which ansible
+  - ansible --version
+  - which yamllint
+  - yamllint --version
+  - which molecule
+  - molecule --version
 stages:
-  - lint
-lint:
-  stage: lint
+  - trixie
+  - bookworm
+  # - bullseye
+  - jammy
+trixie:
+  image: registry.git.coop/webarch/containers/images/trixie:20230822
+  stage: trixie
+  script:
+    - molecule test --all
+bookworm:
+  image: registry.git.coop/webarch/containers/images/bookworm:20230822
+  stage: bookworm
+  script:
+    - molecule test --all
+# The Bullseye test run OK but Molecule never completes
+# https://github.com/ansible/molecule/discussions/4020
+# bullseye:
+#   image: registry.git.coop/webarch/containers/images/bullseye:20230822
+#   stage: bullseye
+#   script:
+#     - molecule test --all
+jammy:
+  image: registry.git.coop/webarch/containers/images/jammy:20230822
+  stage: jammy
   script:
-    - molecule lint
-# vim: syntax=yaml
+    - molecule test --all
 ...
diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml
new file mode 100644
index 0000000..e78a38f
--- /dev/null
+++ b/molecule/default/converge.yml
@@ -0,0 +1,38 @@
+# Copyright 2018-2023 Chris Croome
+#
+# This file is part of the Webarchitects Apache Ansible role.
+#
+# The Webarchitects Apache 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 Apache 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 Apache Ansible role. If not, see <https://www.gnu.org/licenses/>.
+---
+- name: Run as root
+  # become: true
+  connection: local
+  # gather_facts: true
+  hosts:
+    - localhost
+  vars:
+    ansible_python_interpreter: /usr/bin/python3
+  tasks:
+
+    - name: Debug ansible_effective_user_id
+      ansible.builtin.debug:
+        var: ansible_effective_user_id
+
+    - name: Debug ansible_user_id
+      ansible.builtin.debug:
+        var: ansible_user_id
+
+    - name: Debug ansible_user_dir
+      ansible.builtin.debug:
+        var: ansible_user_dir
+
+    - name: Include role as root
+      ansible.builtin.include_role:
+        name: "{{ lookup('ansible.builtin.env', 'CI_PROJECT_NAME') }}"
+      vars:  # noqa var-naming[no-role-prefix]
+        openproject: true
+...
diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml
index 612062e..fb0b885 100644
--- a/molecule/default/molecule.yml
+++ b/molecule/default/molecule.yml
@@ -8,18 +8,14 @@
 #
 # You should have received a copy of the GNU General Public License along with the Webarchitects Apache Ansible role. If not, see <https://www.gnu.org/licenses/>.
 ---
-dependency:
+dependency: 
   name: galaxy
 platforms:
   - name: instance
-    image: registry.git.coop/webarch/containers/images/ansible:0.23.0
-    pre_build_image: true
 provisioner:
   name: ansible
-lint: |
-  set -e
-  find -type f -name '*.j2' -exec ansiblej2lint.py {} +
-  yamllint -f colored -c .yamllint .
-  ansible-lint -c .ansible-lint --force-color .
-# vim: syntax=yaml
+  options:
+    D: True
+verifier:
+  name: ansible
 ...
diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml
new file mode 100644
index 0000000..5e352aa
--- /dev/null
+++ b/molecule/default/requirements.yml
@@ -0,0 +1,15 @@
+# Copyright 2018-2023 Chris Croome
+#
+# This file is part of the Webarchitects Apache Ansible role.
+#
+# The Webarchitects Apache 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 Apache 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 Apache Ansible role. If not, see <https://www.gnu.org/licenses/>.
+---
+- name: apt 
+  src: https://git.coop/webarch/apt.git
+  version: 3.0.2  # apt
+  scm: git
+...
diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml
new file mode 100644
index 0000000..7a68dac
--- /dev/null
+++ b/molecule/default/verify.yml
@@ -0,0 +1,31 @@
+# Copyright 2018-2023 Chris Croome
+#
+# This file is part of the Webarchitects Apache Ansible role.
+#
+# The Webarchitects Apache 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 Apache 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 Apache Ansible role. If not, see <https://www.gnu.org/licenses/>.
+---
+
+- name: Verify as root
+  # become: true
+  connection: local
+  # gather_facts: true
+  hosts:
+    - localhost
+  vars:
+    ansible_python_interpreter: /usr/bin/python3
+  tasks:
+
+    - name: Check apache2ctl status
+      ansible.builtin.command: apache2ctl status
+      check_mode: false
+      changed_when: false
+      register: molecule_apache2ctl_status
+
+    - name: Debug apache2ctl status result
+      ansible.builtin.debug:
+        var: molecule_apache2ctl_status.stdout_lines
+...
-- 
GitLab