From 260846f9037552cd75732ae819961d012e3534fb Mon Sep 17 00:00:00 2001 From: Chris Croome <chris@webarchitects.co.uk> Date: Tue, 27 Jun 2023 22:09:25 +0100 Subject: [PATCH] pre-commit and molecule updates --- .ansible-docs.yml.bak | 23 +++++++++++++++++++ .ansible-lint | 11 +++++++-- .gitlab-ci.yml | 43 +++++++++++++++++++++++++++-------- .pre-commit-config.yaml | 14 +++++++++--- .pymarkdown | 7 ++++++ meta/requirements.yml | 15 ++++++++++++ molecule/default/converge.yml | 34 +++++++++------------------ molecule/default/molecule.yml | 1 - molecule/default/verify.yml | 28 +++++++++++++++++++++++ tasks/pkg.yml | 2 +- tasks/verify.yml | 2 +- 11 files changed, 140 insertions(+), 40 deletions(-) create mode 100644 .ansible-docs.yml.bak create mode 100644 .pymarkdown create mode 100644 meta/requirements.yml create mode 100644 molecule/default/verify.yml diff --git a/.ansible-docs.yml.bak b/.ansible-docs.yml.bak new file mode 100644 index 0000000..4ebe93a --- /dev/null +++ b/.ansible-docs.yml.bak @@ -0,0 +1,23 @@ +--- +output_file: README.md +output_mode: inject +output_template: | + <!-- BEGIN_ANSIBLE_DOCS --> + + This is my role: {{ role }} + + <!-- 'metadata' contains all the things in meta/main.yml --> + {{ metadata.galaxy_info.license }} + + <!-- All the usual Jinja2 filters are available --> + {{ metadata.galaxy_info.galaxy_tags | sort }} + + <!-- Including files is also possible in relation to the role's directory with Jinja2's include directive --> + {% include "defaults/main.yml" %} + + <!-- 'argument_specs' contains all the things in meta/argument_specs.yml --> + {% for entrypoint, specs in argument_specs | items %} + Task file name: {{ entrypoint }}.yml has {{ specs | length }} input variables! + {% endfor %} + <!-- END_ANSIBLE_DOCS --> +... diff --git a/.ansible-lint b/.ansible-lint index 18375a1..0920b1b 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -1,8 +1,15 @@ +# 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/>. --- # https://ansible-lint.readthedocs.io/rules/ skip_list: - - args[module] - - jinja[spacing] - key-order[task] - name[template] - package-latest diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f5f5786..1f4a1d7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,19 +8,44 @@ # # 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/>. --- -image: registry.git.coop/webarch/containers/images/ansible:0.24.0 variables: - ANSIBLE_DEFAULT_VERBOSITY: "2" - ANSIBLE_DIFF_ALWAYS: "1" + ANSIBLE_DISPLAY_SKIPPED_HOSTS: "0" ANSIBLE_FORCE_COLOR: "1" + GIT_STRATEGY: none + MOLECULE_VERBOSITY: "0" PY_COLORS: "1" before_script: - - chmod 700 $(pwd) + - cd + - source ~/.profile + - mkdir -p builds/${CI_PROJECT_ROOT_NAMESPACE} + - cd builds/${CI_PROJECT_ROOT_NAMESPACE} + - git clone ${CI_PROJECT_URL}.git + - ansible-galaxy install -r ${CI_PROJECT_NAME}/meta/requirements.yml + - cd ${CI_PROJECT_NAME} + - cat /etc/debian_version + - which ansible + - ansible --version + - which yamllint + - yamllint --version + - which molecule + - molecule --version stages: - - lint -lint: - stage: lint + - bookworm + - bullseye + - jammy +bookworm: + image: registry.git.coop/webarch/containers/images/bookworm:20230605 + stage: bookworm script: - - molecule converge -# vim: syntax=yaml + - molecule test +bullseye: + image: registry.git.coop/webarch/containers/images/bullseye:20230605 + stage: bullseye + script: + - molecule test +jammy: + image: registry.git.coop/webarch/containers/images/jammy:20230605 + stage: jammy + script: + - molecule test ... diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3ebd0b5..44677b9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,21 +8,29 @@ # # 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/>. --- -# https://yamllint.readthedocs.io/en/stable/integration.html -# https://github.com/adrienverge/yamllint/tags repos: + # https://github.com/adrienverge/yamllint/tags - repo: https://github.com/adrienverge/yamllint.git rev: v1.32.0 hooks: - id: yamllint name: YAML Lint + # https://github.com/ansible/ansible-lint/releases - repo: https://github.com/ansible/ansible-lint.git - rev: v6.17.0 + rev: v6.17.2 hooks: - id: ansible-lint name: Ansible Lint language: python additional_dependencies: + # https://github.com/kellyjonbrazil/jc/releases - jc==1.23.2 + # https://github.com/jmespath/jmespath.py/tags - jmespath==1.0.1 + # https://github.com/jackdewinter/pymarkdown/releases + - repo: https://github.com/jackdewinter/pymarkdown + rev: v0.9.11 + hooks: + - id: pymarkdown + name: Markdown Lint ... diff --git a/.pymarkdown b/.pymarkdown new file mode 100644 index 0000000..e70c272 --- /dev/null +++ b/.pymarkdown @@ -0,0 +1,7 @@ +} + "plugins": { + "md013": { + "enabled": false + } + } +} diff --git a/meta/requirements.yml b/meta/requirements.yml new file mode 100644 index 0000000..eb016f6 --- /dev/null +++ b/meta/requirements.yml @@ -0,0 +1,15 @@ +# 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: apt + src: https://git.coop/webarch/apt.git + version: 2.2.3 # apt + scm: git +... diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 699f311..1bfeed5 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -8,33 +8,21 @@ # # 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: Lint - become: false +- name: Run as root + become: true connection: local - gather_facts: false + gather_facts: true hosts: - localhost tasks: - - name: Check Jinja2 syntax - ansible.builtin.command: find -type f -name '*.j2' -exec ansiblej2lint.py {} + - check_mode: false - args: - chdir: ../.. - changed_when: false + - name: Debug ansible_effective_user_id + ansible.builtin.debug: + var: ansible_effective_user_id - - name: YAML lint - ansible.builtin.command: yamllint -f colored -c .yamllint . - check_mode: false - args: - chdir: ../.. - changed_when: false - - - name: Ansible lint - ansible.builtin.command: ansible-lint -c .ansible-lint --force-color . - check_mode: false - args: - chdir: ../.. - changed_when: false -# vim: syntax=yaml + - name: Include php role as root with install set to deb + ansible.builtin.include_role: + name: php + vars: # noqa var-naming[no-role-prefix] + php: true ... diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 9cacaf5..1e89144 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -16,5 +16,4 @@ provisioner: name: ansible verifier: name: ansible -# vim: syntax=yaml ... diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..366c75a --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,28 @@ +# 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 as root + become: true + connection: local + gather_facts: true + hosts: + - localhost + tasks: + + - name: Run which php + ansible.builtin.command: which php + check_mode: false + changed_when: false + register: molecule_root_which_php + + - name: Debug which php + ansible.builtin.debug: + var: molecule_root_which_php.stdout +... diff --git a/tasks/pkg.yml b/tasks/pkg.yml index a059d07..d693efd 100644 --- a/tasks/pkg.yml +++ b/tasks/pkg.yml @@ -19,7 +19,7 @@ - name: Set a fact for installed PHP packages that are to be removed ansible.builtin.set_fact: - php_pkg_remove: "{{ ansible_local.dpkg.installed | ansible.builtin.intersect(php_pkg_absent) | default ([]) }}" + php_pkg_remove: "{{ ansible_local.dpkg.installed | ansible.builtin.intersect(php_pkg_absent) | default([]) }}" - name: Debug installed PHP packages that are to be removed ansible.builtin.debug: diff --git a/tasks/verify.yml b/tasks/verify.yml index 99212a3..6454318 100644 --- a/tasks/verify.yml +++ b/tasks/verify.yml @@ -23,7 +23,7 @@ - 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'] }}" + argument_spec: "{{ (lookup('ansible.builtin.file', 'meta/argument_specs.yml') | from_yaml)['argument_specs']['main']['options'] }}" provided_arguments: "{{ phphostvars }}" when: -- GitLab