From 7cb81c4f963e57dd268e5ffa6c9234d6f1781947 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 18 Feb 2021 13:09:28 +0100 Subject: [PATCH] Sweeper. --- files/collections.yml | 4 +++ files/pre-commit-config.yaml | 4 +-- files/yamllint | 1 + generate.yml | 4 +++ gitlab.yml | 2 +- indexer.sh | 7 +++-- templates/README.md.j2 | 44 +++++-------------------------- templates/ansible-lint.j2 | 4 +++ templates/gitlab-ci.yml.j2 | 2 +- templates/molecule-action.yml.j2 | 4 +-- templates/molecule.yml.j2 | 3 +++ templates/requirements2png.yml.j2 | 36 +++++++++++++++++++++++++ templates/tox.ini.j2 | 18 +++++++------ vars/main.yml | 8 +++--- 14 files changed, 82 insertions(+), 59 deletions(-) create mode 100644 files/collections.yml create mode 100644 templates/requirements2png.yml.j2 diff --git a/files/collections.yml b/files/collections.yml new file mode 100644 index 0000000..b869f41 --- /dev/null +++ b/files/collections.yml @@ -0,0 +1,4 @@ +--- +collections: + - name: community.docker + - name: community.general diff --git a/files/pre-commit-config.yaml b/files/pre-commit-config.yaml index 056388e..5e991a7 100644 --- a/files/pre-commit-config.yaml +++ b/files/pre-commit-config.yaml @@ -8,13 +8,13 @@ repos: - id: check-added-large-files - repo: https://github.com/adrienverge/yamllint - rev: v1.25.0 + rev: v1.26.0 hooks: - id: yamllint args: [-c=.yamllint] - repo: https://github.com/ansible/ansible-lint - rev: v4.3.7 + rev: v5.0.1 hooks: - id: ansible-lint pass_filenames: false diff --git a/files/yamllint b/files/yamllint index 894450c..a7ff098 100644 --- a/files/yamllint +++ b/files/yamllint @@ -13,3 +13,4 @@ rules: ignore: | .tox/ + .cache/ diff --git a/generate.yml b/generate.yml index 555e038..b97deff 100755 --- a/generate.yml +++ b/generate.yml @@ -148,6 +148,8 @@ dest: .github/FUNDING.yml - source: pre-commit-config.yaml dest: .pre-commit-config.yaml + - source: collections.yml + dest: molecule/default/collections.yml loop_control: label: "{{ item.source }}" @@ -180,6 +182,8 @@ - source: gitlab-ci.yml dest: .gitlab-ci.yml - source: requirements.txt + - source: requirements2png.yml + dest: .github/workflows/requirements2png.yml loop_control: label: "{{ item.source }}" diff --git a/gitlab.yml b/gitlab.yml index 55d3660..f0f7dac 100755 --- a/gitlab.yml +++ b/gitlab.yml @@ -68,4 +68,4 @@ description: "Monthly test" ref: master cron: '{{ letter_minute_mapping[role[0]] }} {{ letter_hour_mapping[role[0]] }} {{ letter_day_mapping[role[0]] }} * *' - cron_timezone: UTC + cron_timezone: Amsterdam diff --git a/indexer.sh b/indexer.sh index 185d4e2..158a757 100755 --- a/indexer.sh +++ b/indexer.sh @@ -9,8 +9,8 @@ directory="/home/robertdb/Documents/github.com/robertdebock" pattern="ansible-role-" # Print the header of the table. -echo "|Role name|Travis|GitHub Action|GitLab CI|Version|" -echo "|---------|------|-------------|---------|-------|" +echo "|Role name|GitHub Action|GitLab CI|Version|" +echo "|---------|-------------|---------|-------|" # Loop over the found roles. cd ${directory} ; ls -d "${pattern}"* | while read rolename ; do @@ -20,12 +20,11 @@ cd ${directory} ; ls -d "${pattern}"* | while read rolename ; do # Save the markdown per column in a variable, better readable loop. galaxy="[${shortrolename}](https://galaxy.ansible.com/robertdebock/${shortrolename})" - travis="[![travis](https://api.travis-ci.com/robertdebock/${rolename}.svg?branch=master)](https://travis-ci.com/robertdebock/${rolename})" github="[![github](https://github.com/robertdebock/${rolename}/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/${rolename}/actions)" gitlab="[![gitlab](https://gitlab.com/robertdebock/${rolename}/badges/master/pipeline.svg)](https://gitlab.com/robertdebock/${rolename})" version="[![version](https://img.shields.io/github/commits-since/robertdebock/${rolename}/latest.svg)](https://github.com/robertdebock/${rolename}/releases)" # Print the line of one role. - echo "|${galaxy}|${travis}|${github}|${gitlab}|${version}|" + echo "|${galaxy}|${github}|${gitlab}|${version}|" done diff --git a/templates/README.md.j2 b/templates/README.md.j2 index 97d9275..ce6b180 100644 --- a/templates/README.md.j2 +++ b/templates/README.md.j2 @@ -2,9 +2,9 @@ {{ meta.galaxy_info.description }} -|Travis|GitHub|GitLab|Quality|Downloads|Version| -|------|------|------|-------|---------|-------| -|[![travis](https://travis-ci.com/{{ travis_namespace }}/ansible-role-{{ role_name }}.svg?branch=master)](https://travis-ci.com/{{ travis_namespace }}/ansible-role-{{ role_name }})|[![github](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/workflows/Ansible%20Molecule/badge.svg)](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/actions)|[![gitlab](https://gitlab.com/{{ github_namespace }}/ansible-role-{{ role_name }}/badges/master/pipeline.svg)](https://gitlab.com/{{ github_namespace }}/ansible-role-{{ role_name }})|[![quality](https://img.shields.io/ansible/quality/{{ galaxy_id.stdout | default('unset') }})](https://galaxy.ansible.com/{{ github_namespace }}/{{ role_name }})|[![downloads](https://img.shields.io/ansible/role/d/{{ galaxy_id.stdout |default('unset') }})](https://galaxy.ansible.com/{{ github_namespace }}/{{ role_name }})|[![Version](https://img.shields.io/github/release/{{ github_namespace }}/ansible-role-{{ role_name }}.svg)](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/releases/)| +|GitHub|GitLab|Quality|Downloads|Version| +|------|------|-------|---------|-------| +|[![github](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/workflows/Ansible%20Molecule/badge.svg)](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/actions)|[![gitlab](https://gitlab.com/{{ github_namespace }}/ansible-role-{{ role_name }}/badges/master/pipeline.svg)](https://gitlab.com/{{ github_namespace }}/ansible-role-{{ role_name }})|[![quality](https://img.shields.io/ansible/quality/{{ galaxy_id.stdout | default('unset') }})](https://galaxy.ansible.com/{{ github_namespace }}/{{ role_name }})|[![downloads](https://img.shields.io/ansible/role/d/{{ galaxy_id.stdout |default('unset') }})](https://galaxy.ansible.com/{{ github_namespace }}/{{ role_name }})|[![Version](https://img.shields.io/github/release/{{ github_namespace }}/ansible-role-{{ role_name }}.svg)](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/releases/)| ## [Example Playbook](#example-playbook) @@ -37,10 +37,10 @@ These variables are set in `defaults/main.yml`: The following roles are used to prepare a system. You may choose to prepare your system in another way, I have tested these roles as well. -| Requirement | Travis | GitHub | +| Requirement | GitHub | GitLab | |-------------|--------|--------| {% for requirement in requirements.roles %} -| [{{ requirement.name }}](https://galaxy.ansible.com/{{ github_namespace }}/{{ requirement.name | regex_replace(github_namespace + '\.') }}) | [![Build Status Travis](https://travis-ci.com/{{ github_namespace }}/{{ requirement.name | regex_replace(github_namespace + '\.', 'ansible-role-') }}.svg?branch=master)](https://travis-ci.com/{{ github_namespace }}/{{ requirement.name | regex_replace(github_namespace + '\.', 'ansible-role-') }}) | [![Build Status GitHub](https://github.com/{{ github_namespace }}/{{ requirement.name | regex_replace(github_namespace + '\.', 'ansible-role-') }}/workflows/Ansible%20Molecule/badge.svg)](https://github.com/{{ github_namespace }}/{{ requirement.name | regex_replace(github_namespace + '\.', 'ansible-role-') }}/actions) | +| [{{ requirement.name }}](https://galaxy.ansible.com/{{ github_namespace }}/{{ requirement.name | regex_replace(github_namespace + '\.') }}) | [![Build Status GitHub](https://github.com/{{ github_namespace }}/{{ requirement.name | regex_replace(github_namespace + '\.', 'ansible-role-') }}/workflows/Ansible%20Molecule/badge.svg)](https://github.com/{{ github_namespace }}/{{ requirement.name | regex_replace(github_namespace + '\.', 'ansible-role-') }}/actions) | [![Build Status GitLab ](https://gitlab.com/{{ github_namespace }}/ansible-role-{{ requirement.name | regex_replace(github_namespace + '\.', 'ansible-role-') }}/badges/master/pipeline.svg)](https://gitlab.com/{{ github_namespace }}/{{ requirement.name | regex_replace(github_namespace + '\.', 'ansible-role-') }}) {% endfor %} {% endif %} @@ -58,7 +58,7 @@ Most roles require some kind of preparation, this is done in `molecule/default/p This role is a part of many compatible roles. Have a look at [the documentation of these roles](https://robertdebock.nl/) for further information. Here is an overview of related roles: -![dependencies](https://raw.githubusercontent.com/{{ github_namespace }}/drawings/artifacts/{{ role_name }}.png "Dependency") +![dependencies](https://raw.githubusercontent.com/{{ github_namespace }}/ansible-role-{{ role_name }}/png/requirements.png "Dependencies") ## [Compatibility](#compatibility) @@ -96,40 +96,8 @@ This role [refers to a version]({{ reference }}) released by {{ project_name }}. This version reference means a role may get outdated. Monthly tests occur to see if [bit-rot](https://en.wikipedia.org/wiki/Software_rot) occured. If you however find a problem, please create an issue, I'll get on it as soon as possible.{% endif %} -## [Testing](#testing) - -[Unit tests](https://travis-ci.com/{{ travis_namespace }}/ansible-role-{{ role_name }}) are done on every commit, pull request, release and periodically. - If you find issues, please register them in [GitHub](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/issues) -Testing is done using [Tox](https://tox.readthedocs.io/en/latest/) and [Molecule](https://github.com/ansible/molecule): - -[Tox](https://tox.readthedocs.io/en/latest/) tests multiple ansible versions. -[Molecule](https://github.com/ansible/molecule) tests multiple distributions. - -To test using the defaults (any installed ansible version, namespace: `{{ docker_namespace }}`, image: `{{ docker_image }}`, tag: `{{ docker_tag }}`): - -``` -molecule test - -# Or select a specific image: -image=ubuntu molecule test -# Or select a specific image and a specific tag: -image="debian" tag="stable" tox -``` - -Or you can test multiple versions of Ansible, and select images: -Tox allows multiple versions of Ansible to be tested. To run the default (namespace: `{{ docker_namespace }}`, image: `{{ docker_image }}`, tag: `{{ docker_tag }}`) tests: - -``` -tox - -# To run CentOS (namespace: `{{ docker_namespace }}`, tag: `{{ docker_tag }}`) -image="centos" tox -# Or customize more: -image="debian" tag="stable" tox -``` - ## [License](#license) {{ meta.galaxy_info.license }} diff --git a/templates/ansible-lint.j2 b/templates/ansible-lint.j2 index fdbb9bd..9e2e361 100644 --- a/templates/ansible-lint.j2 +++ b/templates/ansible-lint.j2 @@ -10,8 +10,12 @@ exclude_paths: {% if preferencesymlstat.stat.exists %} - ./meta/preferences.yml {% endif %} + - ./molecule/default/prepare.yml + - ./molecule/default/converge.yml {% if verify.stat.exists %} - ./molecule/default/verify.yml {% endif %} {% endif %} + - ./molecule/default/collections.yml - ./.tox + - ./.cache diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index a7664fd..3bb1b17 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -12,7 +12,7 @@ molecule: script: - image=${image} tag=${tag} molecule test rules: - - if: $CI_COMMIT_TAG == null + - if: $CI_COMMIT_REF_NAME == "master" retry: 2 parallel: matrix: diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index d403a2c..4706393 100644 --- a/templates/molecule-action.yml.j2 +++ b/templates/molecule-action.yml.j2 @@ -21,7 +21,7 @@ jobs: path: {% raw %}"${{ github.repository }}"{% endraw %} - name: molecule - uses: robertdebock/molecule-action@2.6.8 + uses: robertdebock/molecule-action@2.6.16 with: command: lint test: @@ -51,7 +51,7 @@ jobs: - name: parse apparmor for mysql run: sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld - name: molecule - uses: robertdebock/molecule-action@2.6.8 + uses: robertdebock/molecule-action@2.6.16 with: image: {% raw %}${{ matrix.config.image }}{% endraw %} diff --git a/templates/molecule.yml.j2 b/templates/molecule.yml.j2 index b1c53b7..0ba89ab 100644 --- a/templates/molecule.yml.j2 +++ b/templates/molecule.yml.j2 @@ -4,6 +4,9 @@ dependency: name: galaxy options: role-file: requirements.yml +{% if requirements.collections is defined %} + requirements-file: requirements.yml +{% endif %} lint: | set -e yamllint . diff --git a/templates/requirements2png.yml.j2 b/templates/requirements2png.yml.j2 new file mode 100644 index 0000000..b0baa12 --- /dev/null +++ b/templates/requirements2png.yml.j2 @@ -0,0 +1,36 @@ +--- +{{ ansible_managed | comment }} + +on: + - push + +name: Ansible Graphviz + +jobs: + build: + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + with: + path: {% raw %}${{ github.repository }}{% endraw %} + + - name: create png + uses: robertdebock/graphviz-action@1.0.7 + - name: Commit files + run: | + cd {% raw %}${{ github.repository }}{% endraw %} + + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add requirements.dot requirements.png + git commit -m "Add generated files" + - name: save to png branch + uses: ad-m/github-push-action@master + with: + github_token: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %} + + directory: {% raw %}${{ github.repository }}{% endraw %} + + force: true + branch: png diff --git a/templates/tox.ini.j2 b/templates/tox.ini.j2 index 7dbedb2..91f799b 100644 --- a/templates/tox.ini.j2 +++ b/templates/tox.ini.j2 @@ -1,26 +1,28 @@ {{ ansible_managed | comment }} [tox] -minversion = 3.20 +minversion = 3.21.4 {% if tox_versions is defined %} envlist = py{39}-ansible-{% raw %}{{% endraw %}{% for version in tox_versions %}{{ version }}{% if not loop.last %},{% endif %}{% endfor %}{% raw %}}{% endraw %} {% else %} -envlist = py{39}-ansible-{previous,current} +# 2.11 has been disabled: couldn't resolve module/action 'docker_container'. +envlist = py{39}-ansible-{2.9,2.10} {% endif %} skipsdist = true [testenv] deps = - previous: ansible>=2.9, <2.10 - current: ansible - next: git+https://github.com/ansible/ansible.git@devel - molecule[docker]>=3, <4 - docker>=4.2, <4.3 - ansible-lint + 2.9: ansible == 2.9.* + 2.10: ansible == 2.10.* + 2.11: git+https://github.com/ansible/ansible.git@devel + molecule[docker] + docker == 4.* + ansible-lint == 5.* commands = molecule test setenv = TOX_ENVNAME={envname} PY_COLORS=1 ANSIBLE_FORCE_COLOR=1 + ANSIBLE_ROLES_PATH=../ passenv = namespace image tag diff --git a/vars/main.yml b/vars/main.yml index ff38c77..4640a44 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -67,13 +67,15 @@ distribution_version_mapping: all: - 32 - latest - - rawhide + # RawHide has package-GPG issues. + # - rawhide 32: - 32 33: - latest - 34: - - rawhide + # RawHide has package-GPG issues. + # 34: + # - rawhide OpenSUSE: all: - latest