From 25ff872fb5587ce213930d36525d38bde9a10f30 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 25 Mar 2021 09:24:42 +0100 Subject: [PATCH 01/69] On a mac now. --- files/gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/files/gitignore b/files/gitignore index 982db11..93e1f56 100644 --- a/files/gitignore +++ b/files/gitignore @@ -2,3 +2,4 @@ *.log *.swp .tox +.DS_Store From 9fad3bd70e036245b63901c79994067027abc20d Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 25 Mar 2021 09:27:33 +0100 Subject: [PATCH 02/69] Sweeper. --- files/gitignore | 1 + files/pre-commit-config.yaml | 9 ++------- templates/gitlab-ci.yml.j2 | 4 ++-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/files/gitignore b/files/gitignore index 982db11..c15d16a 100644 --- a/files/gitignore +++ b/files/gitignore @@ -2,3 +2,4 @@ *.log *.swp .tox +.cache diff --git a/files/pre-commit-config.yaml b/files/pre-commit-config.yaml index 5e991a7..ec1005b 100644 --- a/files/pre-commit-config.yaml +++ b/files/pre-commit-config.yaml @@ -13,14 +13,9 @@ repos: - id: yamllint args: [-c=.yamllint] - - repo: https://github.com/ansible/ansible-lint - rev: v5.0.1 - hooks: - - id: ansible-lint - pass_filenames: false - - repo: https://github.com/robertdebock/pre-commit - rev: v1.1.2 + rev: v1.2.1 hooks: - id: ansible_role_find_unused_variable - id: ansible_role_find_empty_files + - id: ansible_role_find_empty_directories diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 3bb1b17..7da8918 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -1,5 +1,5 @@ --- -image: robertdebock/github-action-molecule:2.6.6 +image: robertdebock/github-action-molecule:3.0.6 services: - docker:dind @@ -13,7 +13,7 @@ molecule: - image=${image} tag=${tag} molecule test rules: - if: $CI_COMMIT_REF_NAME == "master" - retry: 2 + retry: 1 parallel: matrix: {% for platform in meta.galaxy_info.platforms %} From cc323577e394b5bcf0e571410fd5623bc5dd6d60 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 25 Mar 2021 09:28:59 +0100 Subject: [PATCH 03/69] Two laptops is no fun. --- files/gitignore | 1 + files/pre-commit-config.yaml | 8 +------- templates/gitlab-ci.yml.j2 | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/files/gitignore b/files/gitignore index 93e1f56..df5a2d1 100644 --- a/files/gitignore +++ b/files/gitignore @@ -3,3 +3,4 @@ *.swp .tox .DS_Store +.cache diff --git a/files/pre-commit-config.yaml b/files/pre-commit-config.yaml index 5e991a7..fc3086f 100644 --- a/files/pre-commit-config.yaml +++ b/files/pre-commit-config.yaml @@ -13,14 +13,8 @@ repos: - id: yamllint args: [-c=.yamllint] - - repo: https://github.com/ansible/ansible-lint - rev: v5.0.1 - hooks: - - id: ansible-lint - pass_filenames: false - - repo: https://github.com/robertdebock/pre-commit - rev: v1.1.2 + rev: v1.2.1 hooks: - id: ansible_role_find_unused_variable - id: ansible_role_find_empty_files diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 3bb1b17..b9a62f0 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -13,7 +13,7 @@ molecule: - image=${image} tag=${tag} molecule test rules: - if: $CI_COMMIT_REF_NAME == "master" - retry: 2 + retry: 1 parallel: matrix: {% for platform in meta.galaxy_info.platforms %} From cf53f19fe6002a1619fa37e4e674baed3105c9c2 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 25 Mar 2021 09:29:49 +0100 Subject: [PATCH 04/69] Not twice. --- files/gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/files/gitignore b/files/gitignore index 8abcc13..ad73ff6 100644 --- a/files/gitignore +++ b/files/gitignore @@ -4,4 +4,3 @@ .tox .cache .DS_Store -.cache From 01d37613426fce144440415e8cd667012cfd01a7 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 25 Mar 2021 20:56:04 +0100 Subject: [PATCH 05/69] Bump version and start with ---. --- files/pre-commit-config.yaml | 2 +- templates/ansible-lint.j2 | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/files/pre-commit-config.yaml b/files/pre-commit-config.yaml index ec1005b..af7ef32 100644 --- a/files/pre-commit-config.yaml +++ b/files/pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: args: [-c=.yamllint] - repo: https://github.com/robertdebock/pre-commit - rev: v1.2.1 + rev: v1.2.2 hooks: - id: ansible_role_find_unused_variable - id: ansible_role_find_empty_files diff --git a/templates/ansible-lint.j2 b/templates/ansible-lint.j2 index 9e2e361..e53d677 100644 --- a/templates/ansible-lint.j2 +++ b/templates/ansible-lint.j2 @@ -1,3 +1,4 @@ +--- {{ ansible_managed | comment }} {% if versionymlstat.stat.exists or exceptionymlstat.stat.exists or preferencesymlstat.stat.exists or verify.stat.exists %} exclude_paths: From bd78efb905fc73921a9793d1c72032ddea862036 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Fri, 2 Apr 2021 08:35:10 +0200 Subject: [PATCH 06/69] Find the first letter of the role, not the first letter of "ansible". --- gitlab.yml | 6 +++- templates/README.md.j2 | 2 +- vars/main.yml | 70 +++++++++++++++++++++--------------------- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/gitlab.yml b/gitlab.yml index f0f7dac..158e265 100755 --- a/gitlab.yml +++ b/gitlab.yml @@ -55,6 +55,10 @@ protects: true masked: true + - name: show details + debug: + msg: "Scheduling {{ role }} on {{ letter_minute_mapping[role[13]] }} {{ letter_hour_mapping[role[13]] }} {{ letter_day_mapping[role[13]] }} * *" + - name: create a new pipeline schedule uri: url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules" @@ -67,5 +71,5 @@ body: description: "Monthly test" ref: master - cron: '{{ letter_minute_mapping[role[0]] }} {{ letter_hour_mapping[role[0]] }} {{ letter_day_mapping[role[0]] }} * *' + cron: '{{ letter_minute_mapping[role[13]] }} {{ letter_hour_mapping[role[13]] }} {{ letter_day_mapping[role[13]] }} * *' cron_timezone: Amsterdam diff --git a/templates/README.md.j2 b/templates/README.md.j2 index ce6b180..e7c72c6 100644 --- a/templates/README.md.j2 +++ b/templates/README.md.j2 @@ -40,7 +40,7 @@ The following roles are used to prepare a system. You may choose to prepare your | Requirement | GitHub | GitLab | |-------------|--------|--------| {% for requirement in requirements.roles %} -| [{{ 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-') }}) +|[{{ 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 }}/{{ 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 %} diff --git a/vars/main.yml b/vars/main.yml index 4640a44..d25fb9a 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -166,38 +166,38 @@ letter_hour_mapping: letter_minute_mapping: a: 1 - b: 2 - c: 3 - d: 4 - e: 5 - f: 6 - g: 7 - h: 8 - i: 9 - j: 10 - k: 11 - l: 12 - m: 13 - n: 14 - o: 15 - p: 16 - q: 17 - r: 18 - s: 19 - t: 20 - u: 21 - v: 23 - w: 24 - x: 25 - y: 26 - z: 27 - 0: 28 - 1: 29 - 2: 30 - 3: 31 - 4: 32 - 5: 33 - 6: 34 - 7: 35 - 8: 36 - 9: 37 + b: 3 + c: 5 + d: 7 + e: 9 + f: 11 + g: 13 + h: 15 + i: 17 + j: 19 + k: 21 + l: 23 + m: 25 + n: 27 + o: 29 + p: 31 + q: 33 + r: 35 + s: 37 + t: 39 + u: 41 + v: 43 + w: 45 + x: 47 + y: 49 + z: 51 + 0: 53 + 1: 55 + 2: 57 + 3: 59 + 4: 59 + 5: 59 + 6: 59 + 7: 59 + 8: 59 + 9: 59 From 4f24f199dcc67b48b51ffa748c1f73aa70146c5c Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Fri, 2 Apr 2021 12:15:53 +0200 Subject: [PATCH 07/69] First delete all pipelines, before adding 1. --- gitlab.yml | 86 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/gitlab.yml b/gitlab.yml index 158e265..c04fe41 100755 --- a/gitlab.yml +++ b/gitlab.yml @@ -1,6 +1,6 @@ #!/usr/bin/env ansible-playbook --- -- name: configure GitLab repository +- name: configure gitlab repository hosts: localhost become: no gather_facts: no @@ -24,40 +24,56 @@ set_fact: encoded_path: "{{ namespace + '%2F' + role }}" - - name: place variable - block: - - name: see if the variable is set already - uri: - url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/variables" - method: GET - body_format: json - headers: - PRIVATE-TOKEN: "{{ gitlab_private_token }}" - body: - key: "GALAXY_API_KEY" - register: check_variable - failed_when: - check_variable.json | length <= 0 - rescue: - - name: place variable - uri: - url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/variables" - method: POST - body_format: json - status_code: - - 201 - headers: - PRIVATE-TOKEN: "{{ gitlab_private_token }}" - body: - key: "GALAXY_API_KEY" - value: "{{ galaxy_api_key }}" - variable_type: env_var - protects: true - masked: true + # - name: place variable + # block: + # - name: see if the variable is set already + # uri: + # url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/variables" + # method: GET + # body_format: json + # headers: + # PRIVATE-TOKEN: "{{ gitlab_private_token }}" + # body: + # key: "GALAXY_API_KEY" + # register: check_variable + # failed_when: + # check_variable.json | length <= 0 + # rescue: + # - name: place variable + # uri: + # url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/variables" + # method: POST + # body_format: json + # status_code: + # - 201 + # headers: + # PRIVATE-TOKEN: "{{ gitlab_private_token }}" + # body: + # key: "GALAXY_API_KEY" + # value: "{{ galaxy_api_key }}" + # variable_type: env_var + # protects: true + # masked: true - - name: show details - debug: - msg: "Scheduling {{ role }} on {{ letter_minute_mapping[role[13]] }} {{ letter_hour_mapping[role[13]] }} {{ letter_day_mapping[role[13]] }} * *" + - name: list pipelines + uri: + url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules" + method: GET + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + register: gitlab_schedules + + - name: delete all pipelines + uri: + url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules/{{ item.id }}" + method: DELETE + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + status_code: + - 204 + loop: "{{ gitlab_schedules.json }}" + loop_control: + label: "{{ item.id }}" - name: create a new pipeline schedule uri: @@ -71,5 +87,5 @@ body: description: "Monthly test" ref: master - cron: '{{ letter_minute_mapping[role[13]] }} {{ letter_hour_mapping[role[13]] }} {{ letter_day_mapping[role[13]] }} * *' + cron: "{{ letter_minute_mapping[role[15]] | default('13') }} {{ letter_hour_mapping[role[13]] }} {{ letter_day_mapping[role[13]] }} * *" cron_timezone: Amsterdam From 4de47709cee19710ecd6ecdecb0063b69dc2ebee Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Fri, 2 Apr 2021 20:07:38 +0200 Subject: [PATCH 08/69] Enable variable. --- gitlab.yml | 60 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/gitlab.yml b/gitlab.yml index c04fe41..4f75735 100755 --- a/gitlab.yml +++ b/gitlab.yml @@ -24,36 +24,36 @@ set_fact: encoded_path: "{{ namespace + '%2F' + role }}" - # - name: place variable - # block: - # - name: see if the variable is set already - # uri: - # url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/variables" - # method: GET - # body_format: json - # headers: - # PRIVATE-TOKEN: "{{ gitlab_private_token }}" - # body: - # key: "GALAXY_API_KEY" - # register: check_variable - # failed_when: - # check_variable.json | length <= 0 - # rescue: - # - name: place variable - # uri: - # url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/variables" - # method: POST - # body_format: json - # status_code: - # - 201 - # headers: - # PRIVATE-TOKEN: "{{ gitlab_private_token }}" - # body: - # key: "GALAXY_API_KEY" - # value: "{{ galaxy_api_key }}" - # variable_type: env_var - # protects: true - # masked: true + - name: place variable + block: + - name: see if the variable is set already + uri: + url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/variables" + method: GET + body_format: json + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + body: + key: "GALAXY_API_KEY" + register: check_variable + failed_when: + check_variable.json | length <= 0 + rescue: + - name: place variable + uri: + url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/variables" + method: POST + body_format: json + status_code: + - 201 + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + body: + key: "GALAXY_API_KEY" + value: "{{ galaxy_api_key }}" + variable_type: env_var + protects: true + masked: true - name: list pipelines uri: From 5a6bc236f03720d2828776382a6f20fcc9f13a6f Mon Sep 17 00:00:00 2001 From: Maxwell Gottlieb <9920591+gotmax23@users.noreply.github.com> Date: Fri, 2 Apr 2021 22:34:21 -0500 Subject: [PATCH 09/69] Fixes typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b6ba46..da722b8 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This script loads input from: - defaults/main.yml - requirements.yml - molecule/default/prepare.yml -- molecule/default/playbook.yml* +- molecule/default/converge.yml* - molecule/default/verify.yml - generate_modules.sh - secure.yml From 71b7419512d4d0553e3c411e1e1456e4d5c1f6c5 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 4 May 2021 13:29:44 +0200 Subject: [PATCH 10/69] Add Fedora 34. --- vars/main.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/vars/main.yml b/vars/main.yml index d25fb9a..6365d73 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -65,17 +65,15 @@ distribution_version_mapping: - latest Fedora: all: - - 32 + - 33 - latest - # RawHide has package-GPG issues. - # - rawhide - 32: - - 32 + - rawhide 33: + - 33 + 34: - latest - # RawHide has package-GPG issues. - # 34: - # - rawhide + 35: + - rawhide OpenSUSE: all: - latest From 67c4b1c3db0e8fee824e051fdfe1f325ded45833 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 4 May 2021 13:30:13 +0200 Subject: [PATCH 11/69] Check for defaults, don't lint. (For CIS role.) --- generate.yml | 5 +++++ templates/ansible-lint.j2 | 3 +++ 2 files changed, 8 insertions(+) diff --git a/generate.yml b/generate.yml index b97deff..3c45d63 100755 --- a/generate.yml +++ b/generate.yml @@ -108,6 +108,11 @@ when: - verify.stat.exists | bool + - name: check molecule/default/defaults.yml + stat: + path: "{{ role_path }}/molecule/default/defaults.yml" + register: defaults + - name: load galaxy_id shell: "set -o pipefail ; ansible-galaxy info robertdebock.{{ role_name }} | grep ' id: ' | awk '{print $NF}'" register: galaxy_id diff --git a/templates/ansible-lint.j2 b/templates/ansible-lint.j2 index e53d677..ea4c1b3 100644 --- a/templates/ansible-lint.j2 +++ b/templates/ansible-lint.j2 @@ -16,6 +16,9 @@ exclude_paths: {% if verify.stat.exists %} - ./molecule/default/verify.yml {% endif %} +{% if defaults.stat.exists %} + - ./molecule/default/defaults.yml +{% endif %} {% endif %} - ./molecule/default/collections.yml - ./.tox From b8dc886b5cd30d28631e344faba29088e122dfe4 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 4 May 2021 13:30:34 +0200 Subject: [PATCH 12/69] How to set schedules for GitLab. --- README-gitlab.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 README-gitlab.md diff --git a/README-gitlab.md b/README-gitlab.md new file mode 100644 index 0000000..45fc9c0 --- /dev/null +++ b/README-gitlab.md @@ -0,0 +1,5 @@ +# Usage + +``` +./gitlab.yml --ask-vault-password -e role=ansible-role-xyz +``` From d5d948363752f9aa6dee0aa8bd29f1d28c42ac1e Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Fri, 14 May 2021 09:47:59 +0200 Subject: [PATCH 13/69] Don't mention requirements-file, it breaks molecule. --- templates/molecule.yml.j2 | 7 ------- templates/tox.ini.j2 | 9 ++++----- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/templates/molecule.yml.j2 b/templates/molecule.yml.j2 index 0ba89ab..5e69912 100644 --- a/templates/molecule.yml.j2 +++ b/templates/molecule.yml.j2 @@ -4,9 +4,6 @@ dependency: name: galaxy options: role-file: requirements.yml -{% if requirements.collections is defined %} - requirements-file: requirements.yml -{% endif %} lint: | set -e yamllint . @@ -23,10 +20,6 @@ platforms: pre_build_image: yes provisioner: name: ansible - config_options: - defaults: - stdout_callback: yaml - bin_ansible_callbacks: yes {% if verify.stat.exists %} verifier: name: ansible diff --git a/templates/tox.ini.j2 b/templates/tox.ini.j2 index 91f799b..e3a640f 100644 --- a/templates/tox.ini.j2 +++ b/templates/tox.ini.j2 @@ -4,8 +4,7 @@ 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 %} -# 2.11 has been disabled: couldn't resolve module/action 'docker_container'. -envlist = py{39}-ansible-{2.9,2.10} +envlist = py{39}-ansible-{2.9,2.10,2.11} {% endif %} skipsdist = true @@ -13,8 +12,8 @@ skipsdist = true [testenv] deps = 2.9: ansible == 2.9.* - 2.10: ansible == 2.10.* - 2.11: git+https://github.com/ansible/ansible.git@devel + 2.10: ansible-base == 2.10.* + 2.11: ansible-core == 2.11.* molecule[docker] docker == 4.* ansible-lint == 5.* @@ -25,4 +24,4 @@ setenv = ANSIBLE_FORCE_COLOR=1 ANSIBLE_ROLES_PATH=../ -passenv = namespace image tag +passenv = namespace image tag DOCKER_HOST From f6b957791854f908c490c6848d73461c99026215 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Wed, 9 Jun 2021 17:06:16 +0200 Subject: [PATCH 14/69] Ansible is required. --- generate.yml | 4 ++-- templates/travis.yml.j2 | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/generate.yml b/generate.yml index 3c45d63..617b3ae 100755 --- a/generate.yml +++ b/generate.yml @@ -153,8 +153,8 @@ dest: .github/FUNDING.yml - source: pre-commit-config.yaml dest: .pre-commit-config.yaml - - source: collections.yml - dest: molecule/default/collections.yml + # - source: collections.yml + # dest: molecule/default/collections.yml loop_control: label: "{{ item.source }}" diff --git a/templates/travis.yml.j2 b/templates/travis.yml.j2 index 981fedd..ad7c006 100644 --- a/templates/travis.yml.j2 +++ b/templates/travis.yml.j2 @@ -16,8 +16,7 @@ cache: install: - pip install --upgrade pip - - pip install yamllint - - pip install ansible-lint + - pip install ansible ansible-lint yamllint script: - yamllint . From 8ca240a86dd059bc19ec06b49e2c08402f43e8d6 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Wed, 7 Jul 2021 09:50:21 +0200 Subject: [PATCH 15/69] Use rockylinux, but allow overriding to i.e. centos. --- README.md | 8 +++++++- vars/main.yml | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index da722b8..eb1eddd 100644 --- a/README.md +++ b/README.md @@ -98,9 +98,15 @@ exceptions: This optional file describes how Travis, Tox and Molecule should behave. +|parameter |type |default|description| +|----------------|---------------|-------|-----------| +|tox_version |list of strings|not set|What versions should Tox test? (Default: all.)| +|enterprise_linux|string |not set|If `EL` is used in `meta/main.yml` where should tests happen on? (Default: `rockylinux`.) + + ```yaml --- -travis_parallel: no tox_versions: - current +enterprise_linx: centos ``` diff --git a/vars/main.yml b/vars/main.yml index 6365d73..45564da 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -26,7 +26,7 @@ platform_image_mapping: Amazon: amazonlinux Archlinux: archlinux Debian: debian - EL: centos + EL: "{{ enterprise_linux | default('rockylinux') }}" Fedora: fedora OpenSUSE: opensuse Ubuntu: ubuntu @@ -57,7 +57,6 @@ distribution_version_mapping: - bullseye EL: all: - - 7 - latest 7: - 7 From c533b0f362b86970a6229a1f65854f835507b9a6 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Tue, 27 Jul 2021 18:48:19 -0500 Subject: [PATCH 16/69] Fix typo in README template I corrected the path `molecule/resources` to `molecule/default` --- templates/README.md.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/README.md.j2 b/templates/README.md.j2 index e7c72c6..8274ab6 100644 --- a/templates/README.md.j2 +++ b/templates/README.md.j2 @@ -8,12 +8,12 @@ ## [Example Playbook](#example-playbook) -This example is taken from `molecule/resources/converge.yml` and is tested on each push, pull request and release. +This example is taken from `molecule/default/converge.yml` and is tested on each push, pull request and release. ```yaml {{ example.content | b64decode | regex_replace('ansible-role-', galaxy_namespace ~ '.') }}``` {% if prepare.content is defined %} -The machine needs to be prepared in CI this is done using `molecule/resources/prepare.yml`: +The machine needs to be prepared in CI this is done using `molecule/default/prepare.yml`: ```yaml {{ prepare.content | b64decode | regex_replace('ansible-role-', galaxy_namespace ~ '.') }}``` From b00862b7bd45a398e6540cb86f18650732d30159 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 14 Sep 2021 16:21:13 +0200 Subject: [PATCH 17/69] No contributors. --- files/pre-commit-config.yaml | 7 ++++--- generate.yml | 6 ------ templates/README.md.j2 | 16 ---------------- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/files/pre-commit-config.yaml b/files/pre-commit-config.yaml index af7ef32..ea7ef8c 100644 --- a/files/pre-commit-config.yaml +++ b/files/pre-commit-config.yaml @@ -1,21 +1,22 @@ --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v4.0.1 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-added-large-files - repo: https://github.com/adrienverge/yamllint - rev: v1.26.0 + rev: v1.26.3 hooks: - id: yamllint args: [-c=.yamllint] - repo: https://github.com/robertdebock/pre-commit - rev: v1.2.2 + rev: v1.2.3 hooks: - id: ansible_role_find_unused_variable - id: ansible_role_find_empty_files - id: ansible_role_find_empty_directories + - id: ansible_role_fix_readability diff --git a/generate.yml b/generate.yml index 617b3ae..64fee46 100755 --- a/generate.yml +++ b/generate.yml @@ -119,12 +119,6 @@ changed_when: no failed_when: no - - name: load github contributors - uri: - url: "https://api.github.com/repos/robertdebock/ansible-role-{{ role_name }}/contributors" - register: github_contributors - failed_when: no - - name: create .github directories file: path: "{{ role_path }}/{{ item }}" diff --git a/templates/README.md.j2 b/templates/README.md.j2 index 8274ab6..bb6fc7e 100644 --- a/templates/README.md.j2 +++ b/templates/README.md.j2 @@ -102,22 +102,6 @@ If you find issues, please register them in [GitHub](https://github.com/{{ githu {{ meta.galaxy_info.license }} -{% if github_contributors is defined %} -{% if github_contributors.json is defined %} -{% if github_contributors.json | length > 1 %} -## [Contributors](#contributors) - -I'd like to thank everybody that made contributions to this repository. It motivates me, improves the code and is just fun to collaborate. - -{% for contributor in github_contributors.json %}{% if contributor.login is defined %}{% if contributor.login != "robertdebock" %} -- [{{ contributor.login }}](https://github.com/{{ contributor.login }}) -{% endif %} -{% endif %} -{% endfor %} -{% endif %} -{% endif %} -{% endif %} - ## [Author Information](#author-information) [{{ meta.galaxy_info.author }}]({{ author_website }}) From 65fcab071a3fac19f7c3ca2a720aaf8d9f0f1742 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 14 Sep 2021 16:21:28 +0200 Subject: [PATCH 18/69] Debian bookworm is coming. --- vars/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vars/main.yml b/vars/main.yml index 45564da..50a08d8 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -50,11 +50,11 @@ distribution_version_mapping: Debian: all: - latest - - bullseye - buster: - - latest + - bookworm bullseye: - - bullseye + - latest + bookworm: + - bookworm EL: all: - latest From 1f01ba1aa34389ce6c0752b238f415a1ad793a3e Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Wed, 15 Sep 2021 09:56:18 +0200 Subject: [PATCH 19/69] Minor changes. --- templates/README.md.j2 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/templates/README.md.j2 b/templates/README.md.j2 index bb6fc7e..310253e 100644 --- a/templates/README.md.j2 +++ b/templates/README.md.j2 @@ -13,7 +13,7 @@ This example is taken from `molecule/default/converge.yml` and is tested on each {{ example.content | b64decode | regex_replace('ansible-role-', galaxy_namespace ~ '.') }}``` {% if prepare.content is defined %} -The machine needs to be prepared in CI this is done using `molecule/default/prepare.yml`: +The machine needs to be prepared. In CI this is done using `molecule/default/prepare.yml`: ```yaml {{ prepare.content | b64decode | regex_replace('ansible-role-', galaxy_namespace ~ '.') }}``` @@ -23,7 +23,7 @@ Also see a [full explanation and example](https://robertdebock.nl/how-to-use-the {% if variables.content is defined %} ## [Role Variables](#role-variables) -These variables are set in `defaults/main.yml`: +The default values for the variables are set in `defaults/main.yml`: ```yaml {{ variables.content | b64decode }}``` {% endif %} @@ -33,9 +33,9 @@ These variables are set in `defaults/main.yml`: - pip packages listed in [requirements.txt](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/blob/master/requirements.txt). {% if requirements is defined %} -## [Status of requirements](#status-of-requirements) +## [Status of used roles](#status-of-requirements) -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. +The following roles are used to prepare a system. You can prepare your system in another way. | Requirement | GitHub | GitLab | |-------------|--------|--------| @@ -79,7 +79,7 @@ The minimum version of Ansible required is {{ meta.galaxy_info.min_ansible_versi {% if exceptions is defined %} ## [Exceptions](#exceptions) -Some variarations of the build matrix do not work. These are the variations and reasons why the build won't work: +Some roles can't run on a specific distribution or version. Here are some exceptions. | variation | reason | |---------------------------|------------------------| @@ -94,7 +94,8 @@ This role [refers to a version]({{ reference }}) released by {{ project_name }}. - [{{ version.name }}]({{ version.url }}). {% endfor %} -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 %} +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 %} If you find issues, please register them in [GitHub](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/issues) From a392232a3c5b5020583c6a5254a3a4c48b667f38 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Wed, 15 Sep 2021 09:56:27 +0200 Subject: [PATCH 20/69] Add a bit of CI. --- .github/workflows/shellcheck.yml | 15 +++++++++++++++ .github/workflows/yamllint.yml | 12 ++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .github/workflows/shellcheck.yml create mode 100644 .github/workflows/yamllint.yml diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 0000000..1db445a --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,15 @@ +on: + push: + branch: + - master + +name: 'Trigger: Push action' + +jobs: + shellcheck: + name: Shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master diff --git a/.github/workflows/yamllint.yml b/.github/workflows/yamllint.yml new file mode 100644 index 0000000..a8bb64a --- /dev/null +++ b/.github/workflows/yamllint.yml @@ -0,0 +1,12 @@ +name: 'Yamllint GitHub Actions' +on: + - pull_request +jobs: + yamllint: + name: 'Yamllint' + runs-on: ubuntu-latest + steps: + - name: 'Checkout' + uses: actions/checkout@master + - name: 'Yamllint' + uses: karancode/yamllint-github-action@master From 1f5f7eb660aacd75087dded6e68b915b6a50fbe8 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Wed, 15 Sep 2021 10:24:00 +0200 Subject: [PATCH 21/69] Add a license. --- .github/workflows/shellcheck.yml | 12 +- .github/workflows/yamllint.yml | 13 +- LICENSE | 202 +++++++++++++++++++++++++++++++ indexer.sh | 12 +- 4 files changed, 215 insertions(+), 24 deletions(-) create mode 100644 LICENSE diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index 1db445a..9f36739 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -1,15 +1,11 @@ +name: 'shellcheck' on: push: - branch: - - master - -name: 'Trigger: Push action' jobs: shellcheck: - name: Shellcheck + name: shellcheck runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Run ShellCheck - uses: ludeeus/action-shellcheck@master + - uses: actions/checkout@v2 + - uses: ludeeus/action-shellcheck@master diff --git a/.github/workflows/yamllint.yml b/.github/workflows/yamllint.yml index a8bb64a..4e4392b 100644 --- a/.github/workflows/yamllint.yml +++ b/.github/workflows/yamllint.yml @@ -1,12 +1,11 @@ -name: 'Yamllint GitHub Actions' +name: 'yamllint' on: - - pull_request + push: + jobs: yamllint: - name: 'Yamllint' + name: yamllint runs-on: ubuntu-latest steps: - - name: 'Checkout' - uses: actions/checkout@master - - name: 'Yamllint' - uses: karancode/yamllint-github-action@master + - uses: actions/checkout@v2 + - uses: karancode/yamllint-github-action@master diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e770af8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2021 Robert de Bock (robert@meinit.nl) + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/indexer.sh b/indexer.sh index 158a757..a981aa9 100755 --- a/indexer.sh +++ b/indexer.sh @@ -1,22 +1,16 @@ -#!/bin/sh +#!/bin/sh -x # A script to regenerate a list of roles and their CI status. -# Where are the roles stored locally? -directory="/home/robertdb/Documents/github.com/robertdebock" - -# What is the pattern of the directory names? -pattern="ansible-role-" - # Print the header of the table. echo "|Role name|GitHub Action|GitLab CI|Version|" echo "|---------|-------------|---------|-------|" # Loop over the found roles. -cd ${directory} ; ls -d "${pattern}"* | while read rolename ; do +find ~/Documents/github.com/robertdebock/ansible-role-* | awk 'BEGIN { FS="/" } ; { print $NF }' | while read -r rolename ; do # Find the short name, i.e. "httpd" instead of "ansible-role-httpd" - shortrolename=$(echo "${rolename}" | sed "s/^${pattern}//") + shortrolename=$(echo "${rolename}" | sed "s/^ansible-role//") # Save the markdown per column in a variable, better readable loop. galaxy="[${shortrolename}](https://galaxy.ansible.com/robertdebock/${shortrolename})" From 7a912c4b3266e62d43b61f79b48c83cff400a696 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Wed, 15 Sep 2021 10:41:20 +0200 Subject: [PATCH 22/69] Fix a few yaml issues. --- .github/workflows/shellcheck.yml | 2 ++ .github/workflows/yamllint.yml | 2 ++ .yamllint | 15 +++++++++++++++ generate.yml | 4 +--- 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .yamllint diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index 9f36739..0682ec7 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -1,3 +1,5 @@ +--- + name: 'shellcheck' on: push: diff --git a/.github/workflows/yamllint.yml b/.github/workflows/yamllint.yml index 4e4392b..93638a4 100644 --- a/.github/workflows/yamllint.yml +++ b/.github/workflows/yamllint.yml @@ -1,3 +1,5 @@ +--- + name: 'yamllint' on: push: diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..1277c0a --- /dev/null +++ b/.yamllint @@ -0,0 +1,15 @@ +--- +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable + +ignore: | + vars/vault.yml diff --git a/generate.yml b/generate.yml index 64fee46..0e88e2e 100755 --- a/generate.yml +++ b/generate.yml @@ -53,7 +53,7 @@ include_vars: file: "{{ role_path }}/meta/preferences.yml" when: - - preferencesymlstat.stat.exists | bool + - preferencesymlstat.stat.exists | bool - name: check defaults/main.yml stat: @@ -147,8 +147,6 @@ 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 }}" From aff158eb74a83b462a40188590309a8fd86c2236 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Mon, 20 Sep 2021 09:23:41 +0200 Subject: [PATCH 23/69] Add a simple script to add community.general to a role. --- community.general.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 community.general.sh diff --git a/community.general.sh b/community.general.sh new file mode 100755 index 0000000..ac03579 --- /dev/null +++ b/community.general.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +if [ -f requirements.yml ] ; then + if ! grep 'collections:' requirements.yml > /dev/null ; then + echo "Adding collections header to requirements." + echo "collections:" >> requirements.yml + fi + if ! grep -- ' - name: community.general' requirements.yml > /dev/null ; then + echo "Adding community.general to requirement." + echo " - name: community.general" >> requirements.yml + fi +fi + From 413bbd3ae54efed6cdfcf162c7b5066a3233d48f Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Sun, 3 Oct 2021 06:20:00 +0200 Subject: [PATCH 24/69] Spread vertically. --- files/bug_report.md | 1 + vars/main.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/files/bug_report.md b/files/bug_report.md index f39b5dc..4bb9d98 100644 --- a/files/bug_report.md +++ b/files/bug_report.md @@ -5,6 +5,7 @@ about: Create a report to help me improve --- ## Describe the bug + A clear and concise description of what the bug is. ## Playbook diff --git a/vars/main.yml b/vars/main.yml index 50a08d8..a44bba8 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -26,7 +26,7 @@ platform_image_mapping: Amazon: amazonlinux Archlinux: archlinux Debian: debian - EL: "{{ enterprise_linux | default('rockylinux') }}" + EL: "{{ enterprise_linux | default('enterpriselinux') }}" Fedora: fedora OpenSUSE: opensuse Ubuntu: ubuntu From a0bf12d0d435bb333da4f55400b6d386f1d14d5b Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Sun, 3 Oct 2021 07:10:46 +0200 Subject: [PATCH 25/69] all = 7 + 8 --- vars/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/main.yml b/vars/main.yml index a44bba8..f3e1838 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -57,6 +57,7 @@ distribution_version_mapping: - bookworm EL: all: + - 7 - latest 7: - 7 From 68f545f838570a0ff0f33ca71d68fd2badeb8429 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Wed, 6 Oct 2021 15:26:20 +0200 Subject: [PATCH 26/69] Up the version of pre-commit. --- files/pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/pre-commit-config.yaml b/files/pre-commit-config.yaml index ea7ef8c..e2c58a7 100644 --- a/files/pre-commit-config.yaml +++ b/files/pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: args: [-c=.yamllint] - repo: https://github.com/robertdebock/pre-commit - rev: v1.2.3 + rev: v1.2.5 hooks: - id: ansible_role_find_unused_variable - id: ansible_role_find_empty_files From 213cfbdebdff849fd61232b5178da7c8289b3d0c Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 7 Oct 2021 20:26:29 +0200 Subject: [PATCH 27/69] Refer to the new pre-commit hook. --- files/pre-commit-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/pre-commit-config.yaml b/files/pre-commit-config.yaml index e2c58a7..d4df091 100644 --- a/files/pre-commit-config.yaml +++ b/files/pre-commit-config.yaml @@ -14,9 +14,10 @@ repos: args: [-c=.yamllint] - repo: https://github.com/robertdebock/pre-commit - rev: v1.2.5 + rev: v1.3.1 hooks: - id: ansible_role_find_unused_variable - id: ansible_role_find_empty_files - id: ansible_role_find_empty_directories - id: ansible_role_fix_readability + - id: ansible_role_find_undefined_handlers From 68bdea31fa464ec47e950d52b5a67b0c416d453d Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Mon, 11 Oct 2021 08:53:47 +0200 Subject: [PATCH 28/69] Introduce ansible-later. --- files/later.yml | 12 ++++++++++++ generate.yml | 2 ++ templates/gitlab-ci.yml.j2 | 2 +- templates/molecule-action.yml.j2 | 4 ++-- templates/molecule.yml.j2 | 1 + 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 files/later.yml diff --git a/files/later.yml b/files/later.yml new file mode 100644 index 0000000..83b9158 --- /dev/null +++ b/files/later.yml @@ -0,0 +1,12 @@ +--- +rules: + version: "0.2" + exclude_files: + - meta/argument_specs.yml + - meta/exception.yml + - meta/preferences.yml + - meta/version.yml + - requirements.txt + exclude_filter: + - LINT0009 + - ANSIBLE0007 diff --git a/generate.yml b/generate.yml index 0e88e2e..bfadae4 100755 --- a/generate.yml +++ b/generate.yml @@ -147,6 +147,8 @@ dest: .github/FUNDING.yml - source: pre-commit-config.yaml dest: .pre-commit-config.yaml + - source: later.yml + dest: .later.yml loop_control: label: "{{ item.source }}" diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 7da8918..77bde78 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -1,5 +1,5 @@ --- -image: robertdebock/github-action-molecule:3.0.6 +image: robertdebock/github-action-molecule:3.3.0 services: - docker:dind diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index 4706393..d27de08 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.16 + uses: robertdebock/molecule-action@2.7.0 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.16 + uses: robertdebock/molecule-action@2.7.0 with: image: {% raw %}${{ matrix.config.image }}{% endraw %} diff --git a/templates/molecule.yml.j2 b/templates/molecule.yml.j2 index 5e69912..6cb4fd8 100644 --- a/templates/molecule.yml.j2 +++ b/templates/molecule.yml.j2 @@ -8,6 +8,7 @@ lint: | set -e yamllint . ansible-lint + ansible-later driver: name: docker platforms: From f37664454518c97e5c0b8dc3f9bbeb92e7583fb1 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Wed, 13 Oct 2021 09:21:45 +0200 Subject: [PATCH 29/69] Use action with ansible-later 1.4.0. --- templates/molecule-action.yml.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index d27de08..64cefbf 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.7.0 + uses: robertdebock/molecule-action@2.7.1 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.7.0 + uses: robertdebock/molecule-action@2.7.1 with: image: {% raw %}${{ matrix.config.image }}{% endraw %} From c4b86576e04697e6a6fd79d1d6cedddc68e4f487 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Wed, 13 Oct 2021 09:43:17 +0200 Subject: [PATCH 30/69] GitLab too. --- templates/gitlab-ci.yml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 77bde78..924231b 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -1,5 +1,5 @@ --- -image: robertdebock/github-action-molecule:3.3.0 +image: robertdebock/github-action-molecule:3.3.1 services: - docker:dind From b9b53ee4f92be9365e710415dd04432e9aade189 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Mon, 15 Nov 2021 14:18:15 +0100 Subject: [PATCH 31/69] Newer version of the action. --- templates/molecule-action.yml.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index 64cefbf..5353496 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.7.1 + uses: robertdebock/molecule-action@2.7.2 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.7.1 + uses: robertdebock/molecule-action@2.7.2 with: image: {% raw %}${{ matrix.config.image }}{% endraw %} From 95672a7120e2ef8647a9e586f96414d28c69d288 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Mon, 15 Nov 2021 14:31:55 +0100 Subject: [PATCH 32/69] Fedora 35! --- vars/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vars/main.yml b/vars/main.yml index f3e1838..112e1e4 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -65,14 +65,14 @@ distribution_version_mapping: - latest Fedora: all: - - 33 + - 34 - latest - rawhide - 33: - - 33 34: - - latest + - 34 35: + - latest + 36: - rawhide OpenSUSE: all: From 73a49b5ccff54c160906ff33c8a11914e786d2c6 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Wed, 1 Dec 2021 15:14:31 +0100 Subject: [PATCH 33/69] Add finding unqouted values and quote a value. --- files/pre-commit-config.yaml | 3 ++- templates/gitlab-ci.yml.j2 | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/files/pre-commit-config.yaml b/files/pre-commit-config.yaml index d4df091..4a02356 100644 --- a/files/pre-commit-config.yaml +++ b/files/pre-commit-config.yaml @@ -14,10 +14,11 @@ repos: args: [-c=.yamllint] - repo: https://github.com/robertdebock/pre-commit - rev: v1.3.1 + rev: v1.4.3 hooks: - id: ansible_role_find_unused_variable - id: ansible_role_find_empty_files - id: ansible_role_find_empty_directories - id: ansible_role_fix_readability - id: ansible_role_find_undefined_handlers + - id: ansible_role_find_unquoted_values diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 924231b..d446dd7 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -1,5 +1,5 @@ --- -image: robertdebock/github-action-molecule:3.3.1 +image: "robertdebock/github-action-molecule:3.3.1" services: - docker:dind From 3bc7d768056f7c7ff7f1a361a0a99c57d53fae42 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Fri, 21 Jan 2022 13:06:20 +0100 Subject: [PATCH 34/69] Bump version. --- files/pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/pre-commit-config.yaml b/files/pre-commit-config.yaml index 4a02356..9adf4a9 100644 --- a/files/pre-commit-config.yaml +++ b/files/pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: args: [-c=.yamllint] - repo: https://github.com/robertdebock/pre-commit - rev: v1.4.3 + rev: v1.4.4 hooks: - id: ansible_role_find_unused_variable - id: ansible_role_find_empty_files From 51842e8ea2bead27a0d9b0c86c5a62364be53af7 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Fri, 21 Jan 2022 13:06:41 +0100 Subject: [PATCH 35/69] Remove _ from hostnames. Causes an issue on Debian. --- templates/molecule.yml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/molecule.yml.j2 b/templates/molecule.yml.j2 index 6cb4fd8..7e875e8 100644 --- a/templates/molecule.yml.j2 +++ b/templates/molecule.yml.j2 @@ -12,7 +12,7 @@ lint: | driver: name: docker platforms: - - name: "{{ role_name }}-${image:-{{ docker_image }}}-${tag:-{{ docker_tag }}}${TOX_ENVNAME}" + - name: "{{ role_name | regex_replace('_', '') }}-${image:-{{ docker_image }}}-${tag:-{{ docker_tag }}}${TOX_ENVNAME}" image: "${namespace:-{{ docker_namespace }}}/${image:-{{ docker_image }}}:${tag:-{{ docker_tag }}}" command: /sbin/init volumes: From 7b839cd89483a8dcd8a49043ee89d7045fd6669b Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Fri, 21 Jan 2022 14:09:05 +0100 Subject: [PATCH 36/69] Fedora 35 has Python 3.10, and Ansible is 1 version further. --- templates/tox.ini.j2 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/tox.ini.j2 b/templates/tox.ini.j2 index e3a640f..a9da332 100644 --- a/templates/tox.ini.j2 +++ b/templates/tox.ini.j2 @@ -2,18 +2,18 @@ [tox] 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 %} +envlist = py{310}-ansible-{% raw %}{{% endraw %}{% for version in tox_versions %}{{ version }}{% if not loop.last %},{% endif %}{% endfor %}{% raw %}}{% endraw %} {% else %} -envlist = py{39}-ansible-{2.9,2.10,2.11} +envlist = py{39}-ansible-{2.10,2.11,2.12} {% endif %} skipsdist = true [testenv] deps = - 2.9: ansible == 2.9.* 2.10: ansible-base == 2.10.* 2.11: ansible-core == 2.11.* + 2.12: ansible-core == 2.12.* molecule[docker] docker == 4.* ansible-lint == 5.* From 86179ca2d7cc6ff55f3bbb4f900b332ea2cb6f12 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Fri, 21 Jan 2022 14:27:09 +0100 Subject: [PATCH 37/69] Python 3.10 here too. --- templates/tox.ini.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/tox.ini.j2 b/templates/tox.ini.j2 index a9da332..ec36087 100644 --- a/templates/tox.ini.j2 +++ b/templates/tox.ini.j2 @@ -4,7 +4,7 @@ minversion = 3.21.4 {% if tox_versions is defined %} envlist = py{310}-ansible-{% raw %}{{% endraw %}{% for version in tox_versions %}{{ version }}{% if not loop.last %},{% endif %}{% endfor %}{% raw %}}{% endraw %} {% else %} -envlist = py{39}-ansible-{2.10,2.11,2.12} +envlist = py{310}-ansible-{2.10,2.11,2.12} {% endif %} skipsdist = true From 8070ced90d55b678377395f15db6cc8dab4767de Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Fri, 21 Jan 2022 14:37:48 +0100 Subject: [PATCH 38/69] Update container and action. --- templates/gitlab-ci.yml.j2 | 2 +- templates/molecule-action.yml.j2 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index d446dd7..4f35462 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -1,5 +1,5 @@ --- -image: "robertdebock/github-action-molecule:3.3.1" +image: "robertdebock/github-action-molecule:4.0.0" services: - docker:dind diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index 5353496..5997884 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.7.2 + uses: robertdebock/molecule-action@3.0.0 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.7.2 + uses: robertdebock/molecule-action@3.0.0 with: image: {% raw %}${{ matrix.config.image }}{% endraw %} From 721dd1e0e91e5dbe48b7ba7e138cf8d43dc7cb03 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 25 Jan 2022 21:48:15 +0100 Subject: [PATCH 39/69] Use a container and action with yamllint. --- templates/gitlab-ci.yml.j2 | 3 ++- templates/molecule-action.yml.j2 | 4 ++-- templates/molecule.yml.j2 | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 4f35462..24089f4 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -1,5 +1,5 @@ --- -image: "robertdebock/github-action-molecule:4.0.0" +image: "robertdebock/github-action-molecule:4.0.5" services: - docker:dind @@ -10,6 +10,7 @@ variables: molecule: script: + - test -f requirements.yml && ansible-galaxy install -r requirements.yml - image=${image} tag=${tag} molecule test rules: - if: $CI_COMMIT_REF_NAME == "master" diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index 5997884..570003e 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@3.0.0 + uses: robertdebock/molecule-action@4.0.5 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@3.0.0 + uses: robertdebock/molecule-action@4.0.5 with: image: {% raw %}${{ matrix.config.image }}{% endraw %} diff --git a/templates/molecule.yml.j2 b/templates/molecule.yml.j2 index 7e875e8..ef392da 100644 --- a/templates/molecule.yml.j2 +++ b/templates/molecule.yml.j2 @@ -4,6 +4,7 @@ dependency: name: galaxy options: role-file: requirements.yml + requirements-file: requirements.yml lint: | set -e yamllint . From d0369ddaf9126b8054338fea795641a6669d7cf1 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Wed, 26 Jan 2022 12:55:01 +0100 Subject: [PATCH 40/69] Switch to Ansible 4 and 5, drop ansible-later, update action version. --- files/later.yml | 12 ------------ generate.yml | 2 -- templates/molecule-action.yml.j2 | 4 ++-- templates/molecule.yml.j2 | 1 - templates/tox.ini.j2 | 9 ++++----- 5 files changed, 6 insertions(+), 22 deletions(-) delete mode 100644 files/later.yml diff --git a/files/later.yml b/files/later.yml deleted file mode 100644 index 83b9158..0000000 --- a/files/later.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -rules: - version: "0.2" - exclude_files: - - meta/argument_specs.yml - - meta/exception.yml - - meta/preferences.yml - - meta/version.yml - - requirements.txt - exclude_filter: - - LINT0009 - - ANSIBLE0007 diff --git a/generate.yml b/generate.yml index bfadae4..0e88e2e 100755 --- a/generate.yml +++ b/generate.yml @@ -147,8 +147,6 @@ dest: .github/FUNDING.yml - source: pre-commit-config.yaml dest: .pre-commit-config.yaml - - source: later.yml - dest: .later.yml loop_control: label: "{{ item.source }}" diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index 570003e..cf45e3f 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@4.0.5 + uses: robertdebock/molecule-action@4.0.6 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@4.0.5 + uses: robertdebock/molecule-action@4.0.6 with: image: {% raw %}${{ matrix.config.image }}{% endraw %} diff --git a/templates/molecule.yml.j2 b/templates/molecule.yml.j2 index ef392da..4128689 100644 --- a/templates/molecule.yml.j2 +++ b/templates/molecule.yml.j2 @@ -9,7 +9,6 @@ lint: | set -e yamllint . ansible-lint - ansible-later driver: name: docker platforms: diff --git a/templates/tox.ini.j2 b/templates/tox.ini.j2 index ec36087..631cebb 100644 --- a/templates/tox.ini.j2 +++ b/templates/tox.ini.j2 @@ -4,18 +4,17 @@ minversion = 3.21.4 {% if tox_versions is defined %} envlist = py{310}-ansible-{% raw %}{{% endraw %}{% for version in tox_versions %}{{ version }}{% if not loop.last %},{% endif %}{% endfor %}{% raw %}}{% endraw %} {% else %} -envlist = py{310}-ansible-{2.10,2.11,2.12} +envlist = py{310}-ansible-{4,5} {% endif %} skipsdist = true [testenv] deps = - 2.10: ansible-base == 2.10.* - 2.11: ansible-core == 2.11.* - 2.12: ansible-core == 2.12.* + 4: ansible == 4.* + 5: ansible == 5.* molecule[docker] - docker == 4.* + docker == 5.* ansible-lint == 5.* commands = molecule test setenv = From d3320be02da3d6a964fa8ad7a5f54cca81743e32 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 27 Jan 2022 10:21:43 +0100 Subject: [PATCH 41/69] Simpler, always better. --- templates/gitlab-ci.yml.j2 | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 24089f4..f54d26c 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -10,7 +10,6 @@ variables: molecule: script: - - test -f requirements.yml && ansible-galaxy install -r requirements.yml - image=${image} tag=${tag} molecule test rules: - if: $CI_COMMIT_REF_NAME == "master" From bb50e878ce6f7a5aec425d952cc69951a08cf461 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Mon, 7 Feb 2022 14:23:30 +0100 Subject: [PATCH 42/69] Also for roles that have no requirements. --- templates/README.md.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/README.md.j2 b/templates/README.md.j2 index 310253e..66ba791 100644 --- a/templates/README.md.j2 +++ b/templates/README.md.j2 @@ -32,7 +32,7 @@ The default values for the variables are set in `defaults/main.yml`: - pip packages listed in [requirements.txt](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/blob/master/requirements.txt). -{% if requirements is defined %} +{% if requirements is defined and requirements.roles is defined %} ## [Status of used roles](#status-of-requirements) The following roles are used to prepare a system. You can prepare your system in another way. From 64ee45c4c9ea51ed9fa11c82054c0bb9aecfbdf9 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 29 Mar 2022 10:24:06 +0200 Subject: [PATCH 43/69] New feature in action. --- README.md | 12 ------------ generate.yml | 11 ----------- templates/README.md.j2 | 10 ---------- templates/ansible-lint.j2 | 5 +---- templates/galaxy.yml.j2 | 2 +- templates/gitlab-ci.yml.j2 | 2 +- templates/molecule-action.yml.j2 | 4 ++-- 7 files changed, 5 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index eb1eddd..f13e60e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ This script loads input from: - meta/main.yml* - meta/version.yml -- meta/exception.yml - meta/preferences.yml - defaults/main.yml - requirements.yml @@ -83,17 +82,6 @@ versions: url: "https://github.com/ansible/ansible/releases" ``` -## meta/exception.yml - -This optional file describes why some build are excepted. - -```yaml ---- -exceptions: - - variation: alpine - reason: "Not idempotent" -``` - ## meta/preferences.yml This optional file describes how Travis, Tox and Molecule should behave. diff --git a/generate.yml b/generate.yml index 0e88e2e..3a33015 100755 --- a/generate.yml +++ b/generate.yml @@ -32,17 +32,6 @@ register: versionyml when: - versionymlstat.stat.exists | bool - - name: check meta/exception.yml - stat: - path: "{{ role_path }}/meta/exception.yml" - register: exceptionymlstat - - - name: load meta/exception.yml - include_vars: - file: "{{ role_path }}/meta/exception.yml" - register: exceptionyml - when: - - exceptionymlstat.stat.exists | bool - name: check meta/preferences.yml stat: diff --git a/templates/README.md.j2 b/templates/README.md.j2 index 66ba791..476dd44 100644 --- a/templates/README.md.j2 +++ b/templates/README.md.j2 @@ -76,16 +76,6 @@ The minimum version of Ansible required is {{ meta.galaxy_info.min_ansible_versi - The current version. - The development version. -{% if exceptions is defined %} -## [Exceptions](#exceptions) - -Some roles can't run on a specific distribution or version. Here are some exceptions. - -| variation | reason | -|---------------------------|------------------------| -{% for exception in exceptions %}| {{ exception.variation }} | {{ exception.reason }} | -{% endfor %}{% endif %} - {% if versions is defined %} ## [Included version(s)](#included-versions) diff --git a/templates/ansible-lint.j2 b/templates/ansible-lint.j2 index ea4c1b3..5cc4f2d 100644 --- a/templates/ansible-lint.j2 +++ b/templates/ansible-lint.j2 @@ -1,13 +1,10 @@ --- {{ ansible_managed | comment }} -{% if versionymlstat.stat.exists or exceptionymlstat.stat.exists or preferencesymlstat.stat.exists or verify.stat.exists %} +{% if versionymlstat.stat.exists or preferencesymlstat.stat.exists or verify.stat.exists %} exclude_paths: {% if versionymlstat.stat.exists %} - ./meta/version.yml {% endif %} -{% if exceptionymlstat.stat.exists %} - - ./meta/exception.yml -{% endif %} {% if preferencesymlstat.stat.exists %} - ./meta/preferences.yml {% endif %} diff --git a/templates/galaxy.yml.j2 b/templates/galaxy.yml.j2 index 1fb67de..85269f4 100644 --- a/templates/galaxy.yml.j2 +++ b/templates/galaxy.yml.j2 @@ -11,6 +11,6 @@ jobs: runs-on: ubuntu-20.04 steps: - name: galaxy - uses: robertdebock/galaxy-action@1.1.0 + uses: robertdebock/galaxy-action@1.2.0 with: galaxy_api_key: {% raw %}${{ secrets.galaxy_api_key }}{% endraw %} diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index f54d26c..2adb71c 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -1,5 +1,5 @@ --- -image: "robertdebock/github-action-molecule:4.0.5" +image: "robertdebock/github-action-molecule:4.0.6" services: - docker:dind diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index cf45e3f..463f8c4 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@4.0.6 + uses: robertdebock/molecule-action@4.0.7 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@4.0.6 + uses: robertdebock/molecule-action@4.0.7 with: image: {% raw %}${{ matrix.config.image }}{% endraw %} From 2f18db6af07d990ce8148dcca68cb4cedd18cbec Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 10 May 2022 13:37:55 +0200 Subject: [PATCH 44/69] Cleanup. --- generate.yml | 9 --------- templates/travis.yml.j2 | 27 --------------------------- 2 files changed, 36 deletions(-) delete mode 100644 templates/travis.yml.j2 diff --git a/generate.yml b/generate.yml index 3a33015..52d494a 100755 --- a/generate.yml +++ b/generate.yml @@ -26,13 +26,6 @@ path: "{{ role_path }}/meta/version.yml" register: versionymlstat - - name: load meta/version.yml - include_vars: - file: "{{ role_path }}/meta/version.yml" - register: versionyml - when: - - versionymlstat.stat.exists | bool - - name: check meta/preferences.yml stat: path: "{{ role_path }}/meta/preferences.yml" @@ -153,8 +146,6 @@ - source: LICENSE-2.0.txt dest: LICENSE - source: SECURITY.md - - source: travis.yml - dest: .travis.yml - source: molecule.yml dest: molecule/default/molecule.yml - source: README.md diff --git a/templates/travis.yml.j2 b/templates/travis.yml.j2 deleted file mode 100644 index ad7c006..0000000 --- a/templates/travis.yml.j2 +++ /dev/null @@ -1,27 +0,0 @@ ---- -{{ ansible_managed | comment }} -language: python - -os: linux -dist: xenial - -python: - - "3.9" - -services: - - docker - -cache: - - pip - -install: - - pip install --upgrade pip - - pip install ansible ansible-lint yamllint - -script: - - yamllint . - - ansible-lint - -notifications: - webhooks: https://galaxy.ansible.com/api/v1/notifications/ - email: false From 8db534fdf13e55c76a6cb5a70d8b25d3bf7b2c83 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 10 May 2022 13:38:07 +0200 Subject: [PATCH 45/69] Ubuntu 22 (Jammy) --- vars/main.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vars/main.yml b/vars/main.yml index 112e1e4..41dfe83 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -80,9 +80,12 @@ distribution_version_mapping: Ubuntu: all: - latest + - focal - bionic - focal: + jammy: - latest + focal: + - focal bionic: - bionic From efc462dc93a027e1ab58cf1dc99b93530a43c900 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 30 Jun 2022 10:20:59 +0200 Subject: [PATCH 46/69] Use checkout v3 action` --- .github/workflows/shellcheck.yml | 2 +- .github/workflows/yamllint.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index 0682ec7..158c92f 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -9,5 +9,5 @@ jobs: name: shellcheck runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ludeeus/action-shellcheck@master diff --git a/.github/workflows/yamllint.yml b/.github/workflows/yamllint.yml index 93638a4..741797e 100644 --- a/.github/workflows/yamllint.yml +++ b/.github/workflows/yamllint.yml @@ -9,5 +9,5 @@ jobs: name: yamllint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: karancode/yamllint-github-action@master From 5ee6186b2eebeb0b76817e9da4d434a8bb400855 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 30 Jun 2022 10:22:04 +0200 Subject: [PATCH 47/69] Update pre-commit component versions. --- files/pre-commit-config.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/files/pre-commit-config.yaml b/files/pre-commit-config.yaml index 9adf4a9..50b6ac9 100644 --- a/files/pre-commit-config.yaml +++ b/files/pre-commit-config.yaml @@ -1,7 +1,7 @@ --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.3.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -14,7 +14,7 @@ repos: args: [-c=.yamllint] - repo: https://github.com/robertdebock/pre-commit - rev: v1.4.4 + rev: v1.5.1 hooks: - id: ansible_role_find_unused_variable - id: ansible_role_find_empty_files @@ -22,3 +22,4 @@ repos: - id: ansible_role_fix_readability - id: ansible_role_find_undefined_handlers - id: ansible_role_find_unquoted_values + - id: ansible_role_find_horizontal_when From 0baef4084d88f4db73fd517d536c8654eed13f55 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 30 Jun 2022 10:22:43 +0200 Subject: [PATCH 48/69] Update action version. --- templates/molecule-action.yml.j2 | 8 ++++---- templates/requirements2png.yml.j2 | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index 463f8c4..7d84fe2 100644 --- a/templates/molecule-action.yml.j2 +++ b/templates/molecule-action.yml.j2 @@ -16,12 +16,12 @@ jobs: runs-on: ubuntu-20.04 steps: - name: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: {% raw %}"${{ github.repository }}"{% endraw %} - name: molecule - uses: robertdebock/molecule-action@4.0.7 + uses: robertdebock/molecule-action@4.0.8 with: command: lint test: @@ -42,7 +42,7 @@ jobs: {% endfor %} steps: - name: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: {% raw %}"${{ github.repository }}"{% endraw %} @@ -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@4.0.7 + uses: robertdebock/molecule-action@4.0.8 with: image: {% raw %}${{ matrix.config.image }}{% endraw %} diff --git a/templates/requirements2png.yml.j2 b/templates/requirements2png.yml.j2 index b0baa12..20e53be 100644 --- a/templates/requirements2png.yml.j2 +++ b/templates/requirements2png.yml.j2 @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-20.04 steps: - name: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: {% raw %}${{ github.repository }}{% endraw %} From 4e9357f193ff3db3177a47c78a8d38396a59895a Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 30 Jun 2022 10:23:04 +0200 Subject: [PATCH 49/69] Prepare for ansible-lint-6.3.0 --- templates/ansible-lint.j2 | 2 ++ vars/main.yml | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/templates/ansible-lint.j2 b/templates/ansible-lint.j2 index 5cc4f2d..172b963 100644 --- a/templates/ansible-lint.j2 +++ b/templates/ansible-lint.j2 @@ -20,3 +20,5 @@ exclude_paths: - ./molecule/default/collections.yml - ./.tox - ./.cache + - ./.github + - ./requirements.yml diff --git a/vars/main.yml b/vars/main.yml index 41dfe83..37549ee 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -28,7 +28,7 @@ platform_image_mapping: Debian: debian EL: "{{ enterprise_linux | default('enterpriselinux') }}" Fedora: fedora - OpenSUSE: opensuse + opensuse: opensuse Ubuntu: ubuntu # This maps the Galaxy distribution and version to Docker images. @@ -40,7 +40,7 @@ distribution_version_mapping: all: - 1 - latest - 2018.03: + "2018.03": - 1 Candidate: - latest @@ -59,22 +59,22 @@ distribution_version_mapping: all: - 7 - latest - 7: + "7": - 7 - 8: + "8": - latest Fedora: all: - - 34 + - 35 - latest - rawhide - 34: - - 34 - 35: + "35": + - 35 + "36": - latest - 36: + "37": - rawhide - OpenSUSE: + opensuse: all: - latest Ubuntu: From 153037c4160d1d90c98df4ff58795560bb0dd8b8 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 4 Aug 2022 06:54:04 +0200 Subject: [PATCH 50/69] Drop versions. --- README.md | 27 +++++++-------------------- generate.yml | 5 ----- templates/ansible-lint.j2 | 5 +---- 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index f13e60e..f8829d5 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ Generate documentation and continuous integration files for an Ansible Role. This script loads input from: - meta/main.yml* -- meta/version.yml - meta/preferences.yml - defaults/main.yml - requirements.yml @@ -69,32 +68,20 @@ author: Robert de Bock (robert@meinit.nl) author_website: "https://robertdebock.nl/" ``` -## meta/version.yml - -This optional file can be placed when a role contains a version. - -```yaml ---- -project_name: Ansible -reference: "defaults/main.yml" -versions: - - name: ansible - url: "https://github.com/ansible/ansible/releases" -``` - ## meta/preferences.yml This optional file describes how Travis, Tox and Molecule should behave. -|parameter |type |default|description| -|----------------|---------------|-------|-----------| -|tox_version |list of strings|not set|What versions should Tox test? (Default: all.)| -|enterprise_linux|string |not set|If `EL` is used in `meta/main.yml` where should tests happen on? (Default: `rockylinux`.) +|parameter |type |default|description | +|--------------------|---------------|-------|-----------------------------------------------------------------------------------------| +|tox_ansible_versions|list of strings|not set|What versions should Tox test? (Default: all.) | +|enterprise_linux |string |not set|If `EL` is used in `meta/main.yml` where should tests happen on? (Default: `rockylinux`.)| ```yaml --- -tox_versions: - - current +tox_ansible_versions: + - 4 + - 5 enterprise_linx: centos ``` diff --git a/generate.yml b/generate.yml index 52d494a..1fed5a1 100755 --- a/generate.yml +++ b/generate.yml @@ -21,11 +21,6 @@ file: "{{ role_path }}/meta/main.yml" name: meta - - name: check meta/version.yml - stat: - path: "{{ role_path }}/meta/version.yml" - register: versionymlstat - - name: check meta/preferences.yml stat: path: "{{ role_path }}/meta/preferences.yml" diff --git a/templates/ansible-lint.j2 b/templates/ansible-lint.j2 index 172b963..81399f6 100644 --- a/templates/ansible-lint.j2 +++ b/templates/ansible-lint.j2 @@ -1,10 +1,7 @@ --- {{ ansible_managed | comment }} -{% if versionymlstat.stat.exists or preferencesymlstat.stat.exists or verify.stat.exists %} +{% if preferencesymlstat.stat.exists or verify.stat.exists %} exclude_paths: -{% if versionymlstat.stat.exists %} - - ./meta/version.yml -{% endif %} {% if preferencesymlstat.stat.exists %} - ./meta/preferences.yml {% endif %} From 16cf5173a0e6e73cc6a5df4e18baeb86945e8a5d Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 4 Aug 2022 06:54:16 +0200 Subject: [PATCH 51/69] Script from David, thanks! --- get-galaxy-platforms.py | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 get-galaxy-platforms.py diff --git a/get-galaxy-platforms.py b/get-galaxy-platforms.py new file mode 100755 index 0000000..294ce03 --- /dev/null +++ b/get-galaxy-platforms.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + +# Stolen from David: https://raw.githubusercontent.com/dmsimard/ansible-sandbox/master/get-galaxy-platforms/get-galaxy-platforms.py + +# Copyright 2019 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# Queries the Galaxy API to get all the platforms while handling server-side pagination +import json +import requests + +GALAXY = "https://galaxy.ansible.com" +PLATFORMS_ENDPOINT = GALAXY + "/api/v1/platforms" + +session = requests.Session() + +def get_platforms(): + page = session.get(PLATFORMS_ENDPOINT).json() + yield page["results"] + + while page["next_link"] is not None: + next_url = GALAXY + page['next_link'] + page = session.get(next_url).json() + yield page["results"] + +def main(): + platforms = {} + for results in get_platforms(): + for result in results: + name = result["name"] + version = result["release"] + if name not in platforms: + platforms[name] = { + "name": name, + "versions": [] + } + if version not in platforms[name]["versions"]: + platforms[name]["versions"].append(version) + + print(json.dumps(platforms, indent=2)) + +if __name__ == "__main__": + main() From 124c3c648c380e302bda08989b4d2e0a058f4d86 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 4 Aug 2022 06:54:41 +0200 Subject: [PATCH 52/69] Updates. --- files/pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/pre-commit-config.yaml b/files/pre-commit-config.yaml index 50b6ac9..a9f2dd8 100644 --- a/files/pre-commit-config.yaml +++ b/files/pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: args: [-c=.yamllint] - repo: https://github.com/robertdebock/pre-commit - rev: v1.5.1 + rev: v1.5.2 hooks: - id: ansible_role_find_unused_variable - id: ansible_role_find_empty_files From af213509599da0ffe917de30aa37bd48569b40a8 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 4 Aug 2022 06:54:50 +0200 Subject: [PATCH 53/69] RHEL 9. --- vars/main.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vars/main.yml b/vars/main.yml index 37549ee..760cad6 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -58,11 +58,14 @@ distribution_version_mapping: EL: all: - 7 + - 8 - latest "7": - 7 "8": - - latest + - 8 + "9": + - 9 Fedora: all: - 35 From 803ca78cbaafb4b07edafdb34e52765d8eb42ede Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 4 Aug 2022 06:55:09 +0200 Subject: [PATCH 54/69] A better description. --- templates/tox.ini.j2 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/templates/tox.ini.j2 b/templates/tox.ini.j2 index 631cebb..0c4c984 100644 --- a/templates/tox.ini.j2 +++ b/templates/tox.ini.j2 @@ -1,10 +1,10 @@ {{ ansible_managed | comment }} [tox] minversion = 3.21.4 -{% if tox_versions is defined %} -envlist = py{310}-ansible-{% raw %}{{% endraw %}{% for version in tox_versions %}{{ version }}{% if not loop.last %},{% endif %}{% endfor %}{% raw %}}{% endraw %} +{% if tox_ansible_versions is defined %} +envlist = py{310}-ansible-{% raw %}{{% endraw %}{% for version in tox_ansible_versions %}{{ version }}{% if not loop.last %},{% endif %}{% endfor %}{% raw %}}{% endraw %} {% else %} -envlist = py{310}-ansible-{4,5} +envlist = py{310}-ansible-{4,5,6} {% endif %} skipsdist = true @@ -13,6 +13,7 @@ skipsdist = true deps = 4: ansible == 4.* 5: ansible == 5.* + 6: ansible == 6.* molecule[docker] docker == 5.* ansible-lint == 5.* From 5ca9509fce3ba51b70f300f44b4bc0c2bf950036 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 4 Aug 2022 06:55:21 +0200 Subject: [PATCH 55/69] Use ansible-lint --- templates/molecule-action.yml.j2 | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index 7d84fe2..fdf381e 100644 --- a/templates/molecule-action.yml.j2 +++ b/templates/molecule-action.yml.j2 @@ -17,13 +17,8 @@ jobs: steps: - name: checkout uses: actions/checkout@v3 - with: - path: {% raw %}"${{ github.repository }}"{% endraw %} - - - name: molecule - uses: robertdebock/molecule-action@4.0.8 - with: - command: lint + - name: ansible-lint + uses: ansible-community/ansible-lint-action@main test: needs: - lint From 042122465af01ca6c6e3d8fee073674dcb5f7002 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 4 Aug 2022 06:55:32 +0200 Subject: [PATCH 56/69] Use tox on GitLab too. --- templates/gitlab-ci.yml.j2 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 2adb71c..a8c67c7 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -1,5 +1,5 @@ --- -image: "robertdebock/github-action-molecule:4.0.6" +image: "robertdebock/github-action-molecule:4.0.8" services: - docker:dind @@ -10,7 +10,8 @@ variables: molecule: script: - - image=${image} tag=${tag} molecule test + - if [ -f tox.ini ] ; then tox ; fi + - if [ ! -f tox.ini ; then molecule test ; fi rules: - if: $CI_COMMIT_REF_NAME == "master" retry: 1 From c67d681db8fe8995c3cc38a76393b747f18640d2 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 4 Oct 2022 14:09:57 +0200 Subject: [PATCH 57/69] Not sure, sweeper. --- templates/README.md.j2 | 16 ++++------------ templates/gitlab-ci.yml.j2 | 1 - vars/main.yml | 2 +- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/templates/README.md.j2 b/templates/README.md.j2 index 476dd44..f02ba1d 100644 --- a/templates/README.md.j2 +++ b/templates/README.md.j2 @@ -9,11 +9,13 @@ ## [Example Playbook](#example-playbook) This example is taken from `molecule/default/converge.yml` and is tested on each push, pull request and release. + ```yaml {{ example.content | b64decode | regex_replace('ansible-role-', galaxy_namespace ~ '.') }}``` {% if prepare.content is defined %} The machine needs to be prepared. In CI this is done using `molecule/default/prepare.yml`: + ```yaml {{ prepare.content | b64decode | regex_replace('ansible-role-', galaxy_namespace ~ '.') }}``` @@ -24,6 +26,7 @@ Also see a [full explanation and example](https://robertdebock.nl/how-to-use-the ## [Role Variables](#role-variables) The default values for the variables are set in `defaults/main.yml`: + ```yaml {{ variables.content | b64decode }}``` {% endif %} @@ -40,7 +43,7 @@ The following roles are used to prepare a system. You can prepare your system in | Requirement | GitHub | GitLab | |-------------|--------|--------| {% for requirement in requirements.roles %} -|[{{ 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 }}/{{ 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-') }})| +|[{{ 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 }}/{{ 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 %} @@ -76,17 +79,6 @@ The minimum version of Ansible required is {{ meta.galaxy_info.min_ansible_versi - The current version. - The development version. -{% if versions is defined %} -## [Included version(s)](#included-versions) - -This role [refers to a version]({{ reference }}) released by {{ project_name }}. Check the released version(s) here: -{% for version in versions %} -- [{{ version.name }}]({{ version.url }}). -{% endfor %} - -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 %} - If you find issues, please register them in [GitHub](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/issues) ## [License](#license) diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index a8c67c7..1870566 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -5,7 +5,6 @@ services: - docker:dind variables: - DOCKER_HOST: "tcp://docker:2375" PY_COLORS: 1 molecule: diff --git a/vars/main.yml b/vars/main.yml index 760cad6..7034746 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -65,7 +65,7 @@ distribution_version_mapping: "8": - 8 "9": - - 9 + - latest Fedora: all: - 35 From 2a8178f843ad861e12fc5251742cbdb13e78f344 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 1 Nov 2022 10:42:33 +0100 Subject: [PATCH 58/69] Disable shared runners. --- README-gitlab.md | 13 ++++++++++++ defaults/main.yml | 3 +++ gitlab.yml | 43 +++++++++++++++++++++++++++++++++++--- templates/gitlab-ci.yml.j2 | 4 ++-- 4 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 defaults/main.yml diff --git a/README-gitlab.md b/README-gitlab.md index 45fc9c0..7e7ed63 100644 --- a/README-gitlab.md +++ b/README-gitlab.md @@ -3,3 +3,16 @@ ``` ./gitlab.yml --ask-vault-password -e role=ansible-role-xyz ``` + +## Bulk + +To update all roles: + +``` +echo "PASSWORD" > /tmp/bla.txt + +ls -d ../ansible-role-* | cut -d/ -f2 | while read role ; do + echo "${role}" + ./gitlab.yml --vault-password-file=/tmp/bla.txt -e role="${role}" +done +``` diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..4cc766a --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,3 @@ +--- + +gitlab_runner_id: 18209306 diff --git a/gitlab.yml b/gitlab.yml index 4f75735..430e5de 100755 --- a/gitlab.yml +++ b/gitlab.yml @@ -9,11 +9,12 @@ namespace: robertdebock vars_files: + - defaults/main.yml - vars/main.yml - vars/vault.yml tasks: - - name: see if all veriables are set + - name: see if all variables are set assert: that: - namespace is defined @@ -55,7 +56,7 @@ protects: true masked: true - - name: list pipelines + - name: list pipeline schedules uri: url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules" method: GET @@ -63,7 +64,7 @@ PRIVATE-TOKEN: "{{ gitlab_private_token }}" register: gitlab_schedules - - name: delete all pipelines + - name: delete all pipeline schedules uri: url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules/{{ item.id }}" method: DELETE @@ -89,3 +90,39 @@ ref: master cron: "{{ letter_minute_mapping[role[15]] | default('13') }} {{ letter_hour_mapping[role[13]] }} {{ letter_day_mapping[role[13]] }} * *" cron_timezone: Amsterdam + +# - name: disable runnner +# uri: +# url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/runners/{{ gitlab_runner_id }}" +# method: DELETE +# body_format: json +# status_code: +# - 204 +# - 404 +# headers: +# PRIVATE-TOKEN: "{{ gitlab_private_token }}" +# body: +# runner_id: "{{ gitlab_runner_id }}" + + - name: enable runnner + uri: + url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/runners" + method: POST + body_format: json + status_code: + - 201 + - 400 + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + body: + runner_id: "{{ gitlab_runner_id }}" + + - name: disable shared runnners + uri: + url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}" + method: PUT + body_format: json + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + body: + shared_runners_enabled: false diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 1870566..dda4714 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -1,8 +1,8 @@ --- image: "robertdebock/github-action-molecule:4.0.8" -services: - - docker:dind +# services: +# - docker:dind variables: PY_COLORS: 1 From ec9720777b8d978a5e2b91117c8739ebf401abcf Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 1 Nov 2022 11:10:31 +0100 Subject: [PATCH 59/69] /usr/bin/bash: line 131: [: missing ] --- templates/gitlab-ci.yml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index dda4714..d92dfb2 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -10,7 +10,7 @@ variables: molecule: script: - if [ -f tox.ini ] ; then tox ; fi - - if [ ! -f tox.ini ; then molecule test ; fi + - if [ ! -f tox.ini ] ; then molecule test ; fi rules: - if: $CI_COMMIT_REF_NAME == "master" retry: 1 From 4f25fb8469df3e56d6e3eae54de4021547c9c0a2 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 3 Jan 2023 14:50:40 +0100 Subject: [PATCH 60/69] Sweep --- README.md | 3 +- files/pre-commit-config.yaml | 1 - github.yml | 96 ++++++++++++++++++++++++++++++++++++ gitlab-delete-project.yml | 35 +++++++++++++ gitlab.yml | 28 +++++------ templates/README.md.j2 | 1 + templates/gitlab-ci.yml.j2 | 4 -- templates/tox.ini.j2 | 4 +- vars/main.yml | 8 +-- vars/vault.yml | 22 +++++---- 10 files changed, 166 insertions(+), 36 deletions(-) create mode 100755 github.yml create mode 100755 gitlab-delete-project.yml diff --git a/README.md b/README.md index f8829d5..1f3f87d 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,6 @@ This optional file describes how Travis, Tox and Molecule should behave. ```yaml --- tox_ansible_versions: - - 4 - - 5 + - 7 enterprise_linx: centos ``` diff --git a/files/pre-commit-config.yaml b/files/pre-commit-config.yaml index a9f2dd8..7beec98 100644 --- a/files/pre-commit-config.yaml +++ b/files/pre-commit-config.yaml @@ -19,7 +19,6 @@ repos: - id: ansible_role_find_unused_variable - id: ansible_role_find_empty_files - id: ansible_role_find_empty_directories - - id: ansible_role_fix_readability - id: ansible_role_find_undefined_handlers - id: ansible_role_find_unquoted_values - id: ansible_role_find_horizontal_when diff --git a/github.yml b/github.yml new file mode 100755 index 0000000..4d8f201 --- /dev/null +++ b/github.yml @@ -0,0 +1,96 @@ +#!/usr/bin/env ansible-playbook +--- +- name: github + hosts: localhost + become: no + gather_facts: no + + vars_files: + # - defaults/main.yml + - vars/main.yml + - vars/vault.yml + + pre_tasks: + - name: see if all variables are set + assert: + that: + - github_namespace is defined + - repo is defined + - github_token is defined + quiet: yes + + tasks: + - name: list webhooks + uri: + url: "https://api.github.com/repos/{{ github_namespace }}/{{ repo }}/hooks" + headers: + Accept: "application/vnd.github+json" + Authorization: "Bearer {{ github_token }}" + register: github_webhooks + + - name: show delivery url for gitlab webhook + set_fact: + deliveries_url: "{{ item.deliveries_url }}" + loop: "{{ github_webhooks.json }}" + loop_control: + label: "{{ item.id }}" + when: + - '"gitlab.com" in item.config.url' + + - name: list delivery + uri: + url: "{{ deliveries_url }}" + headers: + Accept: "application/vnd.github+json" + Authorization: "Bearer {{ github_token }}" + register: deliveries + + - name: add repo to github-okay.txt + lineinfile: + line: "{{ repo }}" + path: github-okay.txt + create: yes + loop: "{{ deliveries.json }}" + loop_control: + label: "{{ repo }} - {{ item.id }} - {{ item.status_code }}" + when: + - item.event == "push" + - item.status_code == 200 + + - name: remove repo from github-okay.txt + lineinfile: + line: "{{ repo }}" + path: github-okay.txt + state: absent + create: yes + loop: "{{ deliveries.json }}" + loop_control: + label: "{{ repo }} - {{ item.id }} - {{ item.status_code }}" + when: + - item.event == "push" + - item.status_code != 200 + + - name: add repo to github-fail.txt + lineinfile: + line: "{{ repo }}" + path: github-fail.txt + create: yes + loop: "{{ deliveries.json }}" + loop_control: + label: "{{ repo }} - {{ item.id }} - {{ item.status_code }}" + when: + - item.event == "push" + - item.status_code != 200 + + - name: remove repo from github-fail.txt + lineinfile: + line: "{{ repo }}" + path: github-fail.txt + state: absent + create: yes + loop: "{{ deliveries.json }}" + loop_control: + label: "{{ repo }} - {{ item.id }} - {{ item.status_code }}" + when: + - item.event == "push" + - item.status_code == 200 diff --git a/gitlab-delete-project.yml b/gitlab-delete-project.yml new file mode 100755 index 0000000..8a17ff2 --- /dev/null +++ b/gitlab-delete-project.yml @@ -0,0 +1,35 @@ +#!/usr/bin/env ansible-playbook +--- +- name: delete a gitlab repository + hosts: localhost + become: no + gather_facts: no + + vars: + namespace: robertdebock + + vars_files: + - vars/main.yml + - vars/vault.yml + + tasks: + - name: see if all variables are set + assert: + that: + - namespace is defined + - role is defined + quiet: yes + + - name: urlencode path + set_fact: + encoded_path: "{{ namespace + '%2F' + role }}" + + - name: delete project + uri: + url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}" + method: DELETE + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + status_code: + - 202 + - 404 diff --git a/gitlab.yml b/gitlab.yml index 430e5de..919e4ed 100755 --- a/gitlab.yml +++ b/gitlab.yml @@ -76,20 +76,20 @@ loop_control: label: "{{ item.id }}" - - name: create a new pipeline schedule - uri: - url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules" - method: POST - body_format: json - status_code: - - 201 - headers: - PRIVATE-TOKEN: "{{ gitlab_private_token }}" - body: - description: "Monthly test" - ref: master - cron: "{{ letter_minute_mapping[role[15]] | default('13') }} {{ letter_hour_mapping[role[13]] }} {{ letter_day_mapping[role[13]] }} * *" - cron_timezone: Amsterdam +# - name: create a new pipeline schedule +# uri: +# url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules" +# method: POST +# body_format: json +# status_code: +# - 201 +# headers: +# PRIVATE-TOKEN: "{{ gitlab_private_token }}" +# body: +# description: "Monthly test" +# ref: master +# cron: "{{ letter_minute_mapping[role[15]] | default('13') }} {{ letter_hour_mapping[role[13]] }} {{ letter_day_mapping[role[13]] }} * *" +# cron_timezone: Amsterdam # - name: disable runnner # uri: diff --git a/templates/README.md.j2 b/templates/README.md.j2 index f02ba1d..b946996 100644 --- a/templates/README.md.j2 +++ b/templates/README.md.j2 @@ -55,6 +55,7 @@ Most roles require some kind of preparation, this is done in `molecule/default/p {% for dependency in meta.dependencies %} - {{ dependency }} {% endfor %} + {% endif %} ## [Context](#context) diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index d92dfb2..5afee60 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -1,9 +1,6 @@ --- image: "robertdebock/github-action-molecule:4.0.8" -# services: -# - docker:dind - variables: PY_COLORS: 1 @@ -13,7 +10,6 @@ molecule: - if [ ! -f tox.ini ] ; then molecule test ; fi rules: - if: $CI_COMMIT_REF_NAME == "master" - retry: 1 parallel: matrix: {% for platform in meta.galaxy_info.platforms %} diff --git a/templates/tox.ini.j2 b/templates/tox.ini.j2 index 0c4c984..4ca3131 100644 --- a/templates/tox.ini.j2 +++ b/templates/tox.ini.j2 @@ -4,16 +4,16 @@ minversion = 3.21.4 {% if tox_ansible_versions is defined %} envlist = py{310}-ansible-{% raw %}{{% endraw %}{% for version in tox_ansible_versions %}{{ version }}{% if not loop.last %},{% endif %}{% endfor %}{% raw %}}{% endraw %} {% else %} -envlist = py{310}-ansible-{4,5,6} +envlist = py{310}-ansible-{5,6,7} {% endif %} skipsdist = true [testenv] deps = - 4: ansible == 4.* 5: ansible == 5.* 6: ansible == 6.* + 7: ansible == 7.* molecule[docker] docker == 5.* ansible-lint == 5.* diff --git a/vars/main.yml b/vars/main.yml index 7034746..7e7fc13 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -68,14 +68,14 @@ distribution_version_mapping: - latest Fedora: all: - - 35 + - 36 - latest - rawhide - "35": - - 35 "36": - - latest + - 36 "37": + - latest + "38": - rawhide opensuse: all: diff --git a/vars/vault.yml b/vars/vault.yml index f681e5d..6a020b7 100644 --- a/vars/vault.yml +++ b/vars/vault.yml @@ -1,10 +1,14 @@ $ANSIBLE_VAULT;1.1;AES256 -63333963376266386263383966303436353065346139656263333133346433333064633032663938 -3236306464376332383938356264333933633938626435330a373939643261356639373539656333 -31633035633131386363613233653436646338333537613665383337613461643161636332333332 -6135333135636334620a353963383037653830633136333930663439353665323064303234373666 -65313339393334333831316335353831343264373833373131613162646334323362636466326165 -34373062373331666234353338376339663939313463323437323166346432383130323939376437 -34623265396265326538663731306333323435646430373935633738653034323463373261313832 -35613036636566303036363131343762643665616638353837363439613430386533356663346538 -36306661346266653739623937653635323037633232623562396665646238373238 +35626138373665613930386237633532396164326166376163316366366432393338303535303163 +6435353933333036376462376232366338616335356631310a633732336234386438303761666332 +33643039346337393637346535343966616237376532646561363765663639356138353766303239 +6333313664656339360a393362326563643366376531366563373363396530666138663431346261 +30333566626130363638333162623537316539656264393238656136336431366133636330393635 +61366365613938343063353631633466623466623634343062656233303663663166313836346432 +35386133356664393235373364343534306635326365346465623462376162396539646538613664 +33666562633565643732613637313730306465663730363263346665663064326363396164616165 +61323535346661633364643663623730623662373765663861323236613164623266663361653734 +62666439353333666333323432613439393336643536663237393734313234376532333532353339 +65616634616230613632326162313962373665396265343838333363623437353238633231356262 +33353131616565353065346131636133313833633539323832376262386438303333363763613039 +3235 From fe79fff48f8dfcbfc8d1266002f55d699434fdd7 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Fri, 6 Jan 2023 16:22:00 +0100 Subject: [PATCH 61/69] Sweeper. --- gitlab-delete-project.yml | 2 +- gitlab-import.yml | 45 ++++++++++++++++++++ gitlab-pipeline-trigger.yml | 62 +++++++++++++++++++++++++++ gitlab-pull-mirror.yml | 73 ++++++++++++++++++++++++++++++++ gitlab.yml | 56 ++++++++++++------------ templates/gitlab-ci.yml.j2 | 2 +- templates/molecule-action.yml.j2 | 2 +- templates/tox.ini.j2 | 22 ++++++---- 8 files changed, 224 insertions(+), 40 deletions(-) create mode 100755 gitlab-import.yml create mode 100755 gitlab-pipeline-trigger.yml create mode 100755 gitlab-pull-mirror.yml diff --git a/gitlab-delete-project.yml b/gitlab-delete-project.yml index 8a17ff2..b488056 100755 --- a/gitlab-delete-project.yml +++ b/gitlab-delete-project.yml @@ -6,7 +6,7 @@ gather_facts: no vars: - namespace: robertdebock + namespace: robertdebock-iac vars_files: - vars/main.yml diff --git a/gitlab-import.yml b/gitlab-import.yml new file mode 100755 index 0000000..0ecee69 --- /dev/null +++ b/gitlab-import.yml @@ -0,0 +1,45 @@ +#!/usr/bin/env ansible-playbook +--- +- name: Import repository into gitlab project + hosts: localhost + become: no + gather_facts: no + + vars: + github_owner: robertdebock + gitlab_namespace: robertdebock-iac + + vars_files: + - defaults/main.yml + - vars/main.yml + - vars/vault.yml + + tasks: + - name: see if all variables are set + assert: + that: + - gitlab_namespace is defined + - github_owner is defined + - role is defined + quiet: yes + + - name: Get GitHub repo information + uri: + url: "https://api.github.com/repos/{{ github_owner }}/{{ role }}" + headers: + Authorization: "Bearer {{ github_token }}" + register: github_repo + + - name: Import repository + uri: + url: "https://gitlab.com/api/v4/import/github" + method: POST + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + body_format: json + body: + personal_access_token: "{{ github_token }}" + repo_id: "{{ github_repo.json.id }}" + target_namespace: "{{ gitlab_namespace }}" + status_code: + - 201 diff --git a/gitlab-pipeline-trigger.yml b/gitlab-pipeline-trigger.yml new file mode 100755 index 0000000..a9648e5 --- /dev/null +++ b/gitlab-pipeline-trigger.yml @@ -0,0 +1,62 @@ +#!/usr/bin/env ansible-playbook +--- +- name: Kick off a pipeline for a GitLab project + hosts: localhost + become: no + gather_facts: no + + vars: + gitlab_namespace: robertdebock-iac + + vars_files: + - defaults/main.yml + - vars/main.yml + - vars/vault.yml + + tasks: + - name: see if all variables are set + assert: + that: + - gitlab_namespace is defined + - role is defined + quiet: yes + + - name: Get GitLab project number + uri: + url: https://gitlab.com/api/v4/projects/{{ gitlab_namespace }}%2F{{ role }} + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + register: gitlab_project_details + + - name: Create pipeline trigger + uri: + url: "https://gitlab.com/api/v4/projects/{{ gitlab_project_details.json.id }}/triggers" + method: POST + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + body_format: form-urlencoded + body: + description: "Ansible" + status_code: + - 201 + register: pipeline_trigger + + - name: Trigger pipeline + uri: + url: "https://gitlab.com/api/v4/projects/{{ gitlab_project_details.json.id }}/trigger/pipeline" + method: POST + body_format: form-urlencoded + body: + token: "{{ pipeline_trigger.json.token }}" + ref: master + status_code: + - 201 + + - name: Delete pipeline trigger + uri: + url: "https://gitlab.com/api/v4/projects/{{ gitlab_project_details.json.id }}/triggers/{{ pipeline_trigger.json.id }}" + method: DELETE + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + status_code: + - 204 diff --git a/gitlab-pull-mirror.yml b/gitlab-pull-mirror.yml new file mode 100755 index 0000000..b20a7b5 --- /dev/null +++ b/gitlab-pull-mirror.yml @@ -0,0 +1,73 @@ +#!/usr/bin/env ansible-playbook +--- +- name: Create a pull mirror gitlab project + hosts: localhost + become: no + gather_facts: no + + vars: + github_owner: robertdebock + gitlab_namespace: robertdebock-iac + + vars_files: + - defaults/main.yml + - vars/main.yml + - vars/vault.yml + + tasks: + - name: see if all variables are set + assert: + that: + - gitlab_namespace is defined + - github_owner is defined + - role is defined + quiet: yes + + - name: Get GitHub repo information + uri: + url: "https://api.github.com/repos/{{ github_owner }}/{{ role }}" + headers: + Authorization: "Bearer {{ github_token }}" + register: github_repo + +# - name: Show shit +# debug: +# msg: "{{ github_repo.json }}" + + - name: Get GitLab namespace_id + uri: + url: "https://gitlab.com/api/v4/namespaces" + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + body_format: json + body: + search: "{{ gitlab_namespace }}" + register: gitlab_namespace + +# - name: Show shit +# debug: +# msg: "{{ gitlab_namespace.json }}" + + - name: Create a project that pulls from GitHub + uri: + url: "https://gitlab.com/api/v4/projects" + method: POST + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + body_format: json + body: + name: "{{ github_repo.json.name }}" + description: "{{ github_repo.json.description }}" + # TODO: Should the `path` include the namespace: + path: "{{ github_repo.json.name }}" + namespace_id: 59906445 + import_url: "{{ github_repo.json.clone_url }}" + mirror: true + mirror_triggers_builds: true + status_code: + - 201 + register: gitlab_project + +# - name: Show shit +# debug: +# msg: "{{ gitlab_project }}" diff --git a/gitlab.yml b/gitlab.yml index 919e4ed..b881657 100755 --- a/gitlab.yml +++ b/gitlab.yml @@ -6,7 +6,7 @@ gather_facts: no vars: - namespace: robertdebock + namespace: robertdebock-iac vars_files: - defaults/main.yml @@ -23,7 +23,7 @@ - name: urlencode path set_fact: - encoded_path: "{{ namespace + '%2F' + role }}" + encoded_path: "{{ namespace + '%2F' + 'ansible-role-' + role }}" - name: place variable block: @@ -76,20 +76,20 @@ loop_control: label: "{{ item.id }}" -# - name: create a new pipeline schedule -# uri: -# url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules" -# method: POST -# body_format: json -# status_code: -# - 201 -# headers: -# PRIVATE-TOKEN: "{{ gitlab_private_token }}" -# body: -# description: "Monthly test" -# ref: master -# cron: "{{ letter_minute_mapping[role[15]] | default('13') }} {{ letter_hour_mapping[role[13]] }} {{ letter_day_mapping[role[13]] }} * *" -# cron_timezone: Amsterdam + - name: create a new pipeline schedule + uri: + url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules" + method: POST + body_format: json + status_code: + - 201 + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + body: + description: "Monthly test" + ref: master + cron: "{{ letter_minute_mapping[role[:1]] | default('13') }} {{ letter_hour_mapping[role[:1]] }} {{ letter_day_mapping[role[:1]] }} * *" + cron_timezone: Amsterdam # - name: disable runnner # uri: @@ -104,18 +104,18 @@ # body: # runner_id: "{{ gitlab_runner_id }}" - - name: enable runnner - uri: - url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/runners" - method: POST - body_format: json - status_code: - - 201 - - 400 - headers: - PRIVATE-TOKEN: "{{ gitlab_private_token }}" - body: - runner_id: "{{ gitlab_runner_id }}" +# - name: enable runnner +# uri: +# url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/runners" +# method: POST +# body_format: json +# status_code: +# - 201 +# - 400 +# headers: +# PRIVATE-TOKEN: "{{ gitlab_private_token }}" +# body: +# runner_id: "{{ gitlab_runner_id }}" - name: disable shared runnners uri: diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 5afee60..6a005e6 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -1,5 +1,5 @@ --- -image: "robertdebock/github-action-molecule:4.0.8" +image: "robertdebock/github-action-molecule:5.0.0" variables: PY_COLORS: 1 diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index fdf381e..2d07789 100644 --- a/templates/molecule-action.yml.j2 +++ b/templates/molecule-action.yml.j2 @@ -46,7 +46,7 @@ jobs: - name: parse apparmor for mysql run: sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld - name: molecule - uses: robertdebock/molecule-action@4.0.8 + uses: robertdebock/molecule-action@5.0.0 with: image: {% raw %}${{ matrix.config.image }}{% endraw %} diff --git a/templates/tox.ini.j2 b/templates/tox.ini.j2 index 4ca3131..0c1ff7e 100644 --- a/templates/tox.ini.j2 +++ b/templates/tox.ini.j2 @@ -1,22 +1,22 @@ {{ ansible_managed | comment }} [tox] -minversion = 3.21.4 +minversion = 4.2.4 {% if tox_ansible_versions is defined %} -envlist = py{310}-ansible-{% raw %}{{% endraw %}{% for version in tox_ansible_versions %}{{ version }}{% if not loop.last %},{% endif %}{% endfor %}{% raw %}}{% endraw %} +envlist = py{310}-ansible{% raw %}{{% endraw %}{% for version in tox_ansible_versions %}{{ version }}{% if not loop.last %},{% endif %}{% endfor %}{% raw %}}{% endraw %} {% else %} -envlist = py{310}-ansible-{5,6,7} +envlist = py{310}-ansible{5,6,7} {% endif %} skipsdist = true [testenv] deps = - 5: ansible == 5.* - 6: ansible == 6.* - 7: ansible == 7.* + ansible5: ansible == 5.* + ansible6: ansible == 6.* + ansible7: ansible == 7.* molecule[docker] - docker == 5.* - ansible-lint == 5.* + docker == 6.* + ansible-lint == 6.* commands = molecule test setenv = TOX_ENVNAME={envname} @@ -24,4 +24,8 @@ setenv = ANSIBLE_FORCE_COLOR=1 ANSIBLE_ROLES_PATH=../ -passenv = namespace image tag DOCKER_HOST +passenv = + namespace + image + tag + DOCKER_HOST From e2a95426a01a1f062c5c74d5e557f9197b15d4f5 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Mon, 9 Jan 2023 08:50:25 +0100 Subject: [PATCH 62/69] Sweeper. --- gitlab-public.yml | 54 +++++++++++++++++++++++++++++++++++++ gitlab-pull-mirror.yml | 61 +++++++++++++++++++----------------------- gitlab.yml | 40 +++++++++++++-------------- 3 files changed, 102 insertions(+), 53 deletions(-) create mode 100755 gitlab-public.yml diff --git a/gitlab-public.yml b/gitlab-public.yml new file mode 100755 index 0000000..e742f0c --- /dev/null +++ b/gitlab-public.yml @@ -0,0 +1,54 @@ +#!/usr/bin/env ansible-playbook +--- +- name: Create a pull mirror gitlab project + hosts: localhost + become: no + gather_facts: no + + vars: + github_owner: robertdebock + gitlab_namespace: robertdebock-iac + + vars_files: + - defaults/main.yml + - vars/main.yml + - vars/vault.yml + + tasks: + - name: see if all variables are set + assert: + that: + - github_owner is defined + - role is defined + quiet: yes + + - name: Get a detailed list of owned GitLab projects + uri: + url: "https://gitlab.com/api/v4/projects?owned=true&search={{ role }}" + method: GET + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + return_content: yes + register: gitlab_projects + + - name: Pick project_ids from GitLab projects + set_fact: + gitlab_projects: "{{ gitlab_projects.json | selectattr('name', 'equalto', role) | list }}" + + - name: pick a single project. + set_fact: + gitlab_project_id: "{{ gitlab_projects[0].id }}" + + - name: Patch existing project to mirror + uri: + url: "https://gitlab.com/api/v4/projects/{{ gitlab_project_id }}" + method: PUT + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + body_format: json + body: + visibility: public + status_code: + - 200 + register: create_project + changed_when: yes diff --git a/gitlab-pull-mirror.yml b/gitlab-pull-mirror.yml index b20a7b5..9f29778 100755 --- a/gitlab-pull-mirror.yml +++ b/gitlab-pull-mirror.yml @@ -29,45 +29,40 @@ headers: Authorization: "Bearer {{ github_token }}" register: github_repo - -# - name: Show shit -# debug: -# msg: "{{ github_repo.json }}" - - - name: Get GitLab namespace_id + + - name: Get a detailed list of owned GitLab projects uri: - url: "https://gitlab.com/api/v4/namespaces" + url: "https://gitlab.com/api/v4/projects?owned=true&search={{ role }}" + method: GET + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + return_content: yes + register: gitlab_projects + + - name: Pick project_ids from GitLab projects + set_fact: + gitlab_projects: "{{ gitlab_projects.json | selectattr('name', 'equalto', role) | list }}" + + - name: pick a single project. + set_fact: + gitlab_project_id: "{{ gitlab_projects[0].id }}" + + - name: Patch existing project to mirror + uri: + url: "https://gitlab.com/api/v4/projects/{{ gitlab_project_id }}" + method: PUT headers: PRIVATE-TOKEN: "{{ gitlab_private_token }}" body_format: json body: - search: "{{ gitlab_namespace }}" - register: gitlab_namespace - -# - name: Show shit -# debug: -# msg: "{{ gitlab_namespace.json }}" - - - name: Create a project that pulls from GitHub - uri: - url: "https://gitlab.com/api/v4/projects" - method: POST - headers: - PRIVATE-TOKEN: "{{ gitlab_private_token }}" - body_format: json - body: - name: "{{ github_repo.json.name }}" - description: "{{ github_repo.json.description }}" - # TODO: Should the `path` include the namespace: - path: "{{ github_repo.json.name }}" - namespace_id: 59906445 import_url: "{{ github_repo.json.clone_url }}" mirror: true - mirror_triggers_builds: true + mirror_trigger_builds: true status_code: - - 201 - register: gitlab_project + - 200 + register: create_project + changed_when: yes -# - name: Show shit -# debug: -# msg: "{{ gitlab_project }}" + # - name: Show shit + # debug: + # msg: "{{ create_project }}" diff --git a/gitlab.yml b/gitlab.yml index b881657..45a60d4 100755 --- a/gitlab.yml +++ b/gitlab.yml @@ -23,7 +23,7 @@ - name: urlencode path set_fact: - encoded_path: "{{ namespace + '%2F' + 'ansible-role-' + role }}" + encoded_path: "{{ namespace + '%2F' + role }}" - name: place variable block: @@ -56,25 +56,25 @@ protects: true masked: true - - name: list pipeline schedules - uri: - url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules" - method: GET - headers: - PRIVATE-TOKEN: "{{ gitlab_private_token }}" - register: gitlab_schedules - - - name: delete all pipeline schedules - uri: - url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules/{{ item.id }}" - method: DELETE - headers: - PRIVATE-TOKEN: "{{ gitlab_private_token }}" - status_code: - - 204 - loop: "{{ gitlab_schedules.json }}" - loop_control: - label: "{{ item.id }}" +# - name: list pipeline schedules +# uri: +# url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules" +# method: GET +# headers: +# PRIVATE-TOKEN: "{{ gitlab_private_token }}" +# register: gitlab_schedules +# +# - name: delete all pipeline schedules +# uri: +# url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules/{{ item.id }}" +# method: DELETE +# headers: +# PRIVATE-TOKEN: "{{ gitlab_private_token }}" +# status_code: +# - 204 +# loop: "{{ gitlab_schedules.json }}" +# loop_control: +# label: "{{ item.id }}" - name: create a new pipeline schedule uri: From 25ab020dbb34b742172b6fd6a992abbbc5cebf22 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Sat, 14 Jan 2023 10:08:42 +0100 Subject: [PATCH 63/69] Better README. --- templates/README.md.j2 | 14 +++++++------- vars/main.yml | 13 +++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/templates/README.md.j2 b/templates/README.md.j2 index b946996..3274c4a 100644 --- a/templates/README.md.j2 +++ b/templates/README.md.j2 @@ -4,17 +4,17 @@ |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/)| +|[![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/{{ gitlab_namespace }}/ansible-role-{{ role_name }}/badges/master/pipeline.svg)](https://gitlab.com/{{ gitlab_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) -This example is taken from `molecule/default/converge.yml` and is tested on each push, pull request and release. +This example is taken from [`molecule/default/converge.yml`](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/blob/master/molecule/default/converge.yml) and is tested on each push, pull request and release. ```yaml {{ example.content | b64decode | regex_replace('ansible-role-', galaxy_namespace ~ '.') }}``` {% if prepare.content is defined %} -The machine needs to be prepared. In CI this is done using `molecule/default/prepare.yml`: +The machine needs to be prepared. In CI this is done using [`molecule/default/prepare.yml`](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/blob/master/molecule/default/prepare.yml): ```yaml {{ prepare.content | b64decode | regex_replace('ansible-role-', galaxy_namespace ~ '.') }}``` @@ -25,7 +25,7 @@ Also see a [full explanation and example](https://robertdebock.nl/how-to-use-the {% if variables.content is defined %} ## [Role Variables](#role-variables) -The default values for the variables are set in `defaults/main.yml`: +The default values for the variables are set in [`defaults/main.yml`](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/blob/master/defaults/main.yml): ```yaml {{ variables.content | b64decode }}``` @@ -43,7 +43,7 @@ The following roles are used to prepare a system. You can prepare your system in | Requirement | GitHub | GitLab | |-------------|--------|--------| {% for requirement in requirements.roles %} -|[{{ 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 }}/{{ 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-') }})| +|[{{ 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/{{ gitlab_namespace }}/{{ requirement.name | regex_replace(galaxy_namespace + '\.', 'ansible-role-') }}/badges/master/pipeline.svg)](https://gitlab.com/{{ gitlab_namespace }}/{{ requirement.name | regex_replace(galaxy_namespace + '\.', 'ansible-role-') }})| {% endfor %} {% endif %} @@ -71,7 +71,7 @@ This role has been tested on these [container images](https://hub.docker.com/u/r |container|tags| |---------|----| {% for platform in meta.galaxy_info.platforms %} -|{{ platform.name | lower }}|{% for version in platform.versions %}{{ version }}{% if not loop.last %}, {% endif %}{% endfor %}| +|[{{ platform.name }}]({{ image_docker_hub_url_mapping[platform.name | lower] }})|{% for version in platform.versions %}{{ version }}{% if not loop.last %}, {% endif %}{% endfor %}| {% endfor %} The minimum version of Ansible required is {{ meta.galaxy_info.min_ansible_version }}, tests have been done to: @@ -84,7 +84,7 @@ If you find issues, please register them in [GitHub](https://github.com/{{ githu ## [License](#license) -{{ meta.galaxy_info.license }} +[{{ meta.galaxy_info.license }}](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/blob/master/LICENSE). ## [Author Information](#author-information) diff --git a/vars/main.yml b/vars/main.yml index 7e7fc13..355b029 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -15,6 +15,9 @@ galaxy_namespace: robertdebock # Your username/organization name on GitHub. github_namespace: robertdebock +# Your username/group on GitLab. +gitlab_namespace: robertdebock-iac + # Your name and optionally email-address. author: Robert de Bock (robert@meinit.nl) @@ -31,6 +34,16 @@ platform_image_mapping: opensuse: opensuse Ubuntu: ubuntu +image_docker_hub_url_mapping: + alpine: "https://hub.docker.com/repository/docker/robertdebock/alpine/general" + amazon: "https://hub.docker.com/repository/docker/robertdebock/amazonlinux/general" + archlinux: "https://hub.docker.com/repository/docker/robertdebock/archlinux/general" + debian: "https://hub.docker.com/repository/docker/robertdebock/debian/general" + el: "https://hub.docker.com/repository/docker/robertdebock/enterpriselinux/general" + fedora: "https://hub.docker.com/repository/docker/robertdebock/fedora/general" + opensuse: "https://hub.docker.com/repository/docker/robertdebock/opensuse/general" + ubuntu: "https://hub.docker.com/repository/docker/robertdebock/ubuntu/general" + # This maps the Galaxy distribution and version to Docker images. distribution_version_mapping: Alpine: From f430dfeb793eec56e76d9a0916cb64baea50eff7 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Fri, 27 Jan 2023 08:53:17 +0100 Subject: [PATCH 64/69] Use plain name instead of variable. --- gitlab-pull-mirror.yml | 4 ++-- templates/gitlab-ci.yml.j2 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gitlab-pull-mirror.yml b/gitlab-pull-mirror.yml index 9f29778..97d6f78 100755 --- a/gitlab-pull-mirror.yml +++ b/gitlab-pull-mirror.yml @@ -30,7 +30,7 @@ Authorization: "Bearer {{ github_token }}" register: github_repo - - name: Get a detailed list of owned GitLab projects + - name: Get details of GitLab project uri: url: "https://gitlab.com/api/v4/projects?owned=true&search={{ role }}" method: GET @@ -39,7 +39,7 @@ return_content: yes register: gitlab_projects - - name: Pick project_ids from GitLab projects + - name: Pick project_ids from GitLab project set_fact: gitlab_projects: "{{ gitlab_projects.json | selectattr('name', 'equalto', role) | list }}" diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 6a005e6..531daff 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -23,6 +23,6 @@ molecule: galaxy: script: - - ansible-galaxy role import --api-key ${GALAXY_API_KEY} ${CI_PROJECT_NAMESPACE} ${CI_PROJECT_NAME} + - ansible-galaxy role import --api-key ${GALAXY_API_KEY} {{ gitlab_namespace }} ${CI_PROJECT_NAME} rules: - if: $CI_COMMIT_TAG != null From 1a3bd07a61399df419c8a2d77967d3dad606ffbb Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Mon, 13 Feb 2023 13:34:53 +0100 Subject: [PATCH 65/69] Only the group runner. --- gitlab.yml | 66 +++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/gitlab.yml b/gitlab.yml index 45a60d4..0a32c68 100755 --- a/gitlab.yml +++ b/gitlab.yml @@ -56,25 +56,25 @@ protects: true masked: true -# - name: list pipeline schedules -# uri: -# url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules" -# method: GET -# headers: -# PRIVATE-TOKEN: "{{ gitlab_private_token }}" -# register: gitlab_schedules -# -# - name: delete all pipeline schedules -# uri: -# url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules/{{ item.id }}" -# method: DELETE -# headers: -# PRIVATE-TOKEN: "{{ gitlab_private_token }}" -# status_code: -# - 204 -# loop: "{{ gitlab_schedules.json }}" -# loop_control: -# label: "{{ item.id }}" + - name: list pipeline schedules + uri: + url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules" + method: GET + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + register: gitlab_schedules + + - name: delete all pipeline schedules + uri: + url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules/{{ item.id }}" + method: DELETE + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + status_code: + - 204 + loop: "{{ gitlab_schedules.json }}" + loop_control: + label: "{{ item.id }}" - name: create a new pipeline schedule uri: @@ -88,23 +88,23 @@ body: description: "Monthly test" ref: master - cron: "{{ letter_minute_mapping[role[:1]] | default('13') }} {{ letter_hour_mapping[role[:1]] }} {{ letter_day_mapping[role[:1]] }} * *" + cron: "{{ letter_minute_mapping[role[14]] | default('13') }} {{ letter_hour_mapping[role[14]] }} {{ letter_day_mapping[role[13]] }} * *" cron_timezone: Amsterdam -# - name: disable runnner -# uri: -# url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/runners/{{ gitlab_runner_id }}" -# method: DELETE -# body_format: json -# status_code: -# - 204 -# - 404 -# headers: -# PRIVATE-TOKEN: "{{ gitlab_private_token }}" -# body: -# runner_id: "{{ gitlab_runner_id }}" + - name: disable runnner + uri: + url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/runners/{{ gitlab_runner_id }}" + method: DELETE + body_format: json + status_code: + - 204 + - 404 + headers: + PRIVATE-TOKEN: "{{ gitlab_private_token }}" + body: + runner_id: "{{ gitlab_runner_id }}" -# - name: enable runnner +# - name: enable cloudtop runnner # uri: # url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/runners" # method: POST From f8399c6ac00c28ff6e51eb288b27d34ebd52092c Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Mon, 13 Feb 2023 13:35:02 +0100 Subject: [PATCH 66/69] Use the correct namespace. --- templates/gitlab-ci.yml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 531daff..779a6b4 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -23,6 +23,6 @@ molecule: galaxy: script: - - ansible-galaxy role import --api-key ${GALAXY_API_KEY} {{ gitlab_namespace }} ${CI_PROJECT_NAME} + - ansible-galaxy role import --api-key ${GALAXY_API_KEY} {{ galaxy_namespace }} ${CI_PROJECT_NAME} rules: - if: $CI_COMMIT_TAG != null From c766c7e730a6466dccdd82589e75fb58d0bb9dbd Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Tue, 14 Feb 2023 09:50:34 +0100 Subject: [PATCH 67/69] Remove unwanted empty space. --- templates/tox.ini.j2 | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/tox.ini.j2 b/templates/tox.ini.j2 index 0c1ff7e..c01654e 100644 --- a/templates/tox.ini.j2 +++ b/templates/tox.ini.j2 @@ -6,7 +6,6 @@ envlist = py{310}-ansible{% raw %}{{% endraw %}{% for version in tox_ansible_ver {% else %} envlist = py{310}-ansible{5,6,7} {% endif %} - skipsdist = true [testenv] From c9f9433eabfc2df56d2cc5a6b04814b5597c1954 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Mon, 20 Feb 2023 10:52:57 +0100 Subject: [PATCH 68/69] Update Molecule action version. --- templates/molecule-action.yml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index 2d07789..d772e52 100644 --- a/templates/molecule-action.yml.j2 +++ b/templates/molecule-action.yml.j2 @@ -46,7 +46,7 @@ jobs: - name: parse apparmor for mysql run: sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld - name: molecule - uses: robertdebock/molecule-action@5.0.0 + uses: robertdebock/molecule-action@5.0.2 with: image: {% raw %}${{ matrix.config.image }}{% endraw %} From 0ca1125aa892563107ebbfae0e429b455599b9dd Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Mon, 20 Feb 2023 15:38:19 +0100 Subject: [PATCH 69/69] Allow GitHub variables to be mapped. --- README.md | 10 +++- generate.yml | 83 ++++++++++++++++---------------- templates/README.md.j2 | 2 +- templates/molecule-action.yml.j2 | 7 +++ templates/molecule.yml.j2 | 6 +++ templates/tox.ini.j2 | 5 ++ 6 files changed, 69 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 1f3f87d..f95c7b6 100644 --- a/README.md +++ b/README.md @@ -75,12 +75,18 @@ This optional file describes how Travis, Tox and Molecule should behave. |parameter |type |default|description | |--------------------|---------------|-------|-----------------------------------------------------------------------------------------| |tox_ansible_versions|list of strings|not set|What versions should Tox test? (Default: all.) | -|enterprise_linux |string |not set|If `EL` is used in `meta/main.yml` where should tests happen on? (Default: `rockylinux`.)| +|github_variables_mapping|list|not set|A list of `name` and `variable`, `name` refers to the GitHub exposed name, `variable` refers to the name you'd like to pass to molecule, tox and Ansible.| +# Example ```yaml --- tox_ansible_versions: - 7 -enterprise_linx: centos +github_variables_mapping: + - name: secrets.VAULT_LICENSE + variable: VAULT_LICENCE + - name: secrets.MY_VAR + variable: someTHING + ``` diff --git a/generate.yml b/generate.yml index 1fed5a1..610b260 100755 --- a/generate.yml +++ b/generate.yml @@ -1,6 +1,6 @@ #!/usr/bin/env ansible-playbook --- -- name: generate all files +- name: Generate all files hosts: localhost become: no gather_facts: yes @@ -11,93 +11,94 @@ - vars/main.yml tasks: - - name: set role_path and role_name - set_fact: + - name: Set role_path and role_name + ansible.builtin.set_fact: role_path: "{{ lookup('env', 'PWD') }}" role_name: "{{ lookup('env', 'PWD') | basename | regex_replace('ansible-role-') }}" - - name: load meta/main.yml - include_vars: + - name: Load meta/main.yml + ansible.builtin.include_vars: file: "{{ role_path }}/meta/main.yml" name: meta - - name: check meta/preferences.yml - stat: + - name: Check meta/preferences.yml + ansible.builtin.stat: path: "{{ role_path }}/meta/preferences.yml" register: preferencesymlstat - - name: load meta/preferences.yml - include_vars: + - name: Load meta/preferences.yml + ansible.builtin.include_vars: file: "{{ role_path }}/meta/preferences.yml" when: - preferencesymlstat.stat.exists | bool - - name: check defaults/main.yml - stat: + - name: Check defaults/main.yml + ansible.builtin.stat: path: "{{ role_path }}/defaults/main.yml" register: defaultsmainyml - - name: load defaults/main.yml - slurp: + - name: Load defaults/main.yml + ansible.builtin.slurp: src: "{{ role_path }}/defaults/main.yml" register: variables when: - defaultsmainyml.stat.exists | bool - - name: check requirements.yml - stat: + - name: Check requirements.yml + ansible.builtin.stat: path: "{{ role_path }}/requirements.yml" register: check_requirements - - name: load requirements.yml - include_vars: + - name: Load requirements.yml + ansible.builtin.include_vars: file: "{{ role_path }}/requirements.yml" name: requirements when: - check_requirements.stat.exists | bool - - name: load molecule/default/converge.yml - slurp: + - name: Load molecule/default/converge.yml + ansible.builtin.slurp: src: "{{ role_path }}/molecule/default/converge.yml" register: example - - name: check molecule/default/prepare.yml - stat: + - name: Check molecule/default/prepare.yml + ansible.builtin.stat: path: "{{ role_path }}/molecule/default/prepare.yml" register: check_prepare - - name: load molecule/default/prepare.yml - slurp: + - name: Load molecule/default/prepare.yml + ansible.builtin.slurp: src: "{{ role_path }}/molecule/default/prepare.yml" register: prepare when: - check_prepare.stat.exists | bool - - name: check molecule/default/verify.yml - stat: + - name: Check molecule/default/verify.yml + ansible.builtin.stat: path: "{{ role_path }}/molecule/default/verify.yml" register: verify - - name: load molecule/default/verify.yml - slurp: + - name: Load molecule/default/verify.yml + ansible.builtin.slurp: src: "{{ role_path }}/molecule/default/verify.yml" register: verifyyml when: - verify.stat.exists | bool - - name: check molecule/default/defaults.yml - stat: + - name: Check molecule/default/defaults.yml + ansible.builtin.stat: path: "{{ role_path }}/molecule/default/defaults.yml" register: defaults - - name: load galaxy_id - shell: "set -o pipefail ; ansible-galaxy info robertdebock.{{ role_name }} | grep ' id: ' | awk '{print $NF}'" + - name: Load galaxy_id + ansible.builtin.shell: + cmd: "set -o pipefail ; ansible-galaxy info robertdebock.{{ role_name }} | grep ' id: ' | awk '{print $NF}'" register: galaxy_id changed_when: no failed_when: no - - name: create .github directories - file: + - name: Create .github directories + ansible.builtin.file: path: "{{ role_path }}/{{ item }}" state: directory mode: "0755" @@ -106,8 +107,8 @@ - .github/workflows - .github/ISSUE_TEMPLATE - - name: copy file - copy: + - name: Copy file + ansible.builtin.copy: src: "{{ playbook_dir }}/files/{{ item.source }}" dest: "{{ role_path }}/{{ item.dest | default(item.source) }}" mode: "{{ item.mode | default('0644') }}" @@ -127,10 +128,10 @@ loop_control: label: "{{ item.source }}" - - name: render file - template: + - name: Render file + ansible.builtin.template: src: "{{ playbook_dir }}/templates/{{ item.source }}.j2" - dest: "{{ role_path }}/{{ item.dest | default (item.source) }}" + dest: "{{ role_path }}/{{ item.dest | default(item.source) }}" mode: "0644" with_items: - source: ansible-lint @@ -159,7 +160,7 @@ loop_control: label: "{{ item.source }}" - - name: pre-commit install - command: pre-commit install - args: + - name: Install pre-commit + ansible.builtin.command: + cmd: pre-commit install creates: .git/hooks/pre-commit diff --git a/templates/README.md.j2 b/templates/README.md.j2 index 3274c4a..7f208f4 100644 --- a/templates/README.md.j2 +++ b/templates/README.md.j2 @@ -36,7 +36,7 @@ The default values for the variables are set in [`defaults/main.yml`](https://gi - pip packages listed in [requirements.txt](https://github.com/{{ github_namespace }}/ansible-role-{{ role_name }}/blob/master/requirements.txt). {% if requirements is defined and requirements.roles is defined %} -## [Status of used roles](#status-of-requirements) +## [State of used roles](#state-of-used-roles) The following roles are used to prepare a system. You can prepare your system in another way. diff --git a/templates/molecule-action.yml.j2 b/templates/molecule-action.yml.j2 index d772e52..05a4bd9 100644 --- a/templates/molecule-action.yml.j2 +++ b/templates/molecule-action.yml.j2 @@ -51,3 +51,10 @@ jobs: image: {% raw %}${{ matrix.config.image }}{% endraw %} tag: {% raw %}${{ matrix.config.tag }}{% endraw %} + +{% if github_variables_mapping is defined %} + env: +{% for item in github_variables_mapping %} + {{ item.variable }}: {% raw %}${{ {%endraw %}{{ item.name }} {% raw %}}}{% endraw %} +{% endfor %} +{% endif %} diff --git a/templates/molecule.yml.j2 b/templates/molecule.yml.j2 index 4128689..19cb639 100644 --- a/templates/molecule.yml.j2 +++ b/templates/molecule.yml.j2 @@ -21,6 +21,12 @@ platforms: pre_build_image: yes provisioner: name: ansible +{% if github_variables_mapping is defined %} + env: +{% for item in github_variables_mapping %} + {{ item.variable }}: "{% raw %}${{% endraw %}{{ item.variable }}{% raw %}}{% endraw %}" +{% endfor %} +{% endif %} {% if verify.stat.exists %} verifier: name: ansible diff --git a/templates/tox.ini.j2 b/templates/tox.ini.j2 index c01654e..8fd34d6 100644 --- a/templates/tox.ini.j2 +++ b/templates/tox.ini.j2 @@ -28,3 +28,8 @@ passenv = image tag DOCKER_HOST +{% if github_variables_mapping is defined %} +{% for item in github_variables_mapping %} + {{ item.variable }} +{% endfor %} +{% endif %}