From f3a1169454511639a8a36795fcd19d05fbbe4fc7 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 23 Feb 2023 09:00:29 +0100 Subject: [PATCH 1/4] Inception prevention. --- ansible-generator | 1 - 1 file changed, 1 deletion(-) delete mode 160000 ansible-generator diff --git a/ansible-generator b/ansible-generator deleted file mode 160000 index 0ca1125..0000000 --- a/ansible-generator +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0ca1125aa892563107ebbfae0e429b455599b9dd From 7bd953b13d558542c447b151edcd81bb98171817 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 23 Feb 2023 09:01:26 +0100 Subject: [PATCH 2/4] First line. --- LICENSE | 1 - 1 file changed, 1 deletion(-) diff --git a/LICENSE b/LICENSE index 4e25a26..2be1663 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,3 @@ - Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ From a0ca7accedb6fc72e68012a87572fbca2b2539f4 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 23 Feb 2023 09:31:16 +0100 Subject: [PATCH 3/4] Let's Marie Kondo. --- .gitignore | 2 - .yamllint | 15 ----- README-gitlab.md | 18 ----- README.md | 108 +++++++++++++++--------------- ansible.cfg | 1 - community.general.sh | 13 ---- defaults/main.yml | 20 +++++- generate.yml | 2 +- get-galaxy-platforms.py | 54 --------------- github.yml | 96 --------------------------- gitlab-delete-project.yml | 35 ---------- gitlab-import.yml | 45 ------------- gitlab-pipeline-trigger.yml | 62 ----------------- gitlab-public.yml | 54 --------------- gitlab-pull-mirror.yml | 68 ------------------- gitlab.yml | 128 ------------------------------------ indexer.sh | 24 ------- templates/gitlab-ci.yml.j2 | 1 - vars/main.yml | 47 +++++-------- vars/vault.yml | 14 ---- workflows/shellcheck.yml | 13 ++++ workflows/yamllint.yml | 13 ++++ 22 files changed, 115 insertions(+), 718 deletions(-) delete mode 100644 .gitignore delete mode 100644 .yamllint delete mode 100644 README-gitlab.md delete mode 100644 ansible.cfg delete mode 100755 community.general.sh delete mode 100755 get-galaxy-platforms.py delete mode 100755 github.yml delete mode 100755 gitlab-delete-project.yml delete mode 100755 gitlab-import.yml delete mode 100755 gitlab-pipeline-trigger.yml delete mode 100755 gitlab-public.yml delete mode 100755 gitlab-pull-mirror.yml delete mode 100755 gitlab.yml delete mode 100755 indexer.sh delete mode 100644 vars/vault.yml create mode 100644 workflows/shellcheck.yml create mode 100644 workflows/yamllint.yml diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 951f5c4..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.swp -secure.yml diff --git a/.yamllint b/.yamllint deleted file mode 100644 index 1277c0a..0000000 --- a/.yamllint +++ /dev/null @@ -1,15 +0,0 @@ ---- -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/README-gitlab.md b/README-gitlab.md deleted file mode 100644 index 7e7ed63..0000000 --- a/README-gitlab.md +++ /dev/null @@ -1,18 +0,0 @@ -# Usage - -``` -./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/README.md b/README.md index f95c7b6..ed5db70 100644 --- a/README.md +++ b/README.md @@ -2,37 +2,33 @@ Generate documentation and continuous integration files for an Ansible Role. -## Input +The intention is to focus on writing or maintaining the Ansible role, and use this tool to generate chore-like-tasks. -This script loads input from: +## Overview -- meta/main.yml* -- meta/preferences.yml -- defaults/main.yml -- requirements.yml -- molecule/default/prepare.yml -- molecule/default/converge.yml* -- molecule/default/verify.yml -- generate_modules.sh -- secure.yml -- Ansible Galaxy - -(Items with a star are mandatory) - -## Output - -This script writes output to: - -- README.md -- molecule/default/molecule.yml -- CONTRIBUTING.md -- SECURITY.md -- LICENSE -- .travis.yml -- tox.ini -- .ansible-lint* -- .github/workflows/ansible.yml -- .github/workflows/galaxy.yml +```text ++--- role ----------------------+ +--- role -------------------------------+ +| meta/main.yml | | README.md | +| molecule/default/converge.yml | | bug_report.md | +| meta/preferences.yml | | feature_requests.md | +| requirements.yml | | FUNDING.md | +| molecule/default/prepare.yml | | .gitignore | +| molecule/default/verify.yml | | .pre-commit.config.yaml | +| defaults/main.yml | | .yamllint | ++------------------------+------+ | .ansible-lint | + | | CONTRIBUTING.md | ++--- this tool -----+ | | .github/workflows/galaxy.yml | +| defaults/main.yml | ---+ | .gitlab-ci.yml | +| vars/main.yml | | | LICENSE | +| files/* | | | .github/workflows/molecule.yml | +| templates/* | | | molecule/default/molecule.yml | ++-------------------+ | +--- this tool ---+ | .github/workflows/requirements2png.yml | + +------ | generate.yml | --- | SECURITY.md | ++--- Galaxy ---+ | +-----------------+ | settings.yml | +| galaxy_id | --------+ | .github/workflows/todo.yml | ++--------------+ | .tox.ini | + +----------------------------------------+ +``` ## Usage @@ -43,50 +39,54 @@ cd ansible-role-my_role ## Configuration -In `vars/main.yml` you can change these variable to customize the output. +In `defaults/main.yml` you can change these variable to customize the output. -```yaml ---- -# Settings to Docker containers. -docker_namespace: robertdebock -docker_image: fedora -docker_tag: latest +### Settings to Docker containers -# References to travis use a namespace, this is likely your username on Travis. -travis_namespace: robertdebock +- `docker_namespace` +- `docker_image` +- `docker_tag` -# Documentation refers to Ansible Galaxy. this is likely your username on Galaxy. -galaxy_namespace: robertdebock +### Your username on Galaxy -# Your username/organization name on GitHub. -github_namespace: robertdebock +- `galaxy_namespace` -# Your name and optionally email-address. -author: Robert de Bock (robert@meinit.nl) +### Your username/organization name on GitHub -# The full URL to your website. -author_website: "https://robertdebock.nl/" -``` +- `github_namespace` + +### Your username/group on GitLab + +- `gitlab_namespace` + +### Your name and optionally email-address + +- `author`` + +### The full URL to your website + +- `author_website` ## meta/preferences.yml -This optional file describes how Travis, Tox and Molecule should behave. +This (optional) file describes how Tox and Molecule should behave. -|parameter |type |default|description | -|--------------------|---------------|-------|-----------------------------------------------------------------------------------------| -|tox_ansible_versions|list of strings|not set|What versions should Tox test? (Default: all.) | -|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.| +|parameter |type |default|description | +|------------------------|---------------|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------| +|tox_ansible_versions |list of strings|not set|What versions should Tox test? (Default: all.) | +|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 +## Example ```yaml --- tox_ansible_versions: + - 6 - 7 + github_variables_mapping: - name: secrets.VAULT_LICENSE variable: VAULT_LICENCE - name: secrets.MY_VAR variable: someTHING - ``` diff --git a/ansible.cfg b/ansible.cfg deleted file mode 100644 index 0440d48..0000000 --- a/ansible.cfg +++ /dev/null @@ -1 +0,0 @@ -[defaults] diff --git a/community.general.sh b/community.general.sh deleted file mode 100755 index ac03579..0000000 --- a/community.general.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/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 - diff --git a/defaults/main.yml b/defaults/main.yml index 4cc766a..a80f10a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1,21 @@ --- -gitlab_runner_id: 18209306 +# Settings to Docker containers. +docker_namespace: robertdebock +docker_image: fedora +docker_tag: latest + +# Your username on Galaxy. +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) + +# The full URL to your website. +author_website: "https://robertdebock.nl/" diff --git a/generate.yml b/generate.yml index 610b260..04e2b7a 100755 --- a/generate.yml +++ b/generate.yml @@ -134,6 +134,7 @@ dest: "{{ role_path }}/{{ item.dest | default(item.source) }}" mode: "0644" with_items: + - source: README.md - source: ansible-lint dest: .ansible-lint - source: tox.ini @@ -144,7 +145,6 @@ - source: SECURITY.md - source: molecule.yml dest: molecule/default/molecule.yml - - source: README.md - source: CONTRIBUTING.md - source: molecule-action.yml dest: .github/workflows/molecule.yml diff --git a/get-galaxy-platforms.py b/get-galaxy-platforms.py deleted file mode 100755 index 294ce03..0000000 --- a/get-galaxy-platforms.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/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() diff --git a/github.yml b/github.yml deleted file mode 100755 index 4d8f201..0000000 --- a/github.yml +++ /dev/null @@ -1,96 +0,0 @@ -#!/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 deleted file mode 100755 index b488056..0000000 --- a/gitlab-delete-project.yml +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env ansible-playbook ---- -- name: delete a gitlab repository - hosts: localhost - become: no - gather_facts: no - - vars: - namespace: robertdebock-iac - - 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-import.yml b/gitlab-import.yml deleted file mode 100755 index 0ecee69..0000000 --- a/gitlab-import.yml +++ /dev/null @@ -1,45 +0,0 @@ -#!/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 deleted file mode 100755 index a9648e5..0000000 --- a/gitlab-pipeline-trigger.yml +++ /dev/null @@ -1,62 +0,0 @@ -#!/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-public.yml b/gitlab-public.yml deleted file mode 100755 index e742f0c..0000000 --- a/gitlab-public.yml +++ /dev/null @@ -1,54 +0,0 @@ -#!/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 deleted file mode 100755 index 97d6f78..0000000 --- a/gitlab-pull-mirror.yml +++ /dev/null @@ -1,68 +0,0 @@ -#!/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: Get details of GitLab project - 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 project - 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: - import_url: "{{ github_repo.json.clone_url }}" - mirror: true - mirror_trigger_builds: true - status_code: - - 200 - register: create_project - changed_when: yes - - # - name: Show shit - # debug: - # msg: "{{ create_project }}" diff --git a/gitlab.yml b/gitlab.yml deleted file mode 100755 index 0a32c68..0000000 --- a/gitlab.yml +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/env ansible-playbook ---- -- name: configure gitlab repository - hosts: localhost - become: no - gather_facts: no - - vars: - namespace: robertdebock-iac - - vars_files: - - defaults/main.yml - - 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: 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 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: - 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[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: enable cloudtop 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/indexer.sh b/indexer.sh deleted file mode 100755 index a981aa9..0000000 --- a/indexer.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -x - -# A script to regenerate a list of roles and their CI status. - -# Print the header of the table. -echo "|Role name|GitHub Action|GitLab CI|Version|" -echo "|---------|-------------|---------|-------|" - -# Loop over the found roles. -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/^ansible-role//") - - # Save the markdown per column in a variable, better readable loop. - galaxy="[${shortrolename}](https://galaxy.ansible.com/robertdebock/${shortrolename})" - github="[![github](https://github.com/robertdebock/${rolename}/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/${rolename}/actions)" - gitlab="[![gitlab](https://gitlab.com/robertdebock/${rolename}/badges/master/pipeline.svg)](https://gitlab.com/robertdebock/${rolename})" - version="[![version](https://img.shields.io/github/commits-since/robertdebock/${rolename}/latest.svg)](https://github.com/robertdebock/${rolename}/releases)" - - # Print the line of one role. - echo "|${galaxy}|${github}|${gitlab}|${version}|" - -done diff --git a/templates/gitlab-ci.yml.j2 b/templates/gitlab-ci.yml.j2 index 114bc9d..779a6b4 100644 --- a/templates/gitlab-ci.yml.j2 +++ b/templates/gitlab-ci.yml.j2 @@ -10,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/vars/main.yml b/vars/main.yml index 355b029..7ea5b64 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,50 +1,30 @@ --- # Setting to generate files. -# Settings to Docker containers. -docker_namespace: robertdebock -docker_image: fedora -docker_tag: latest - -# References to travis use a namespace, this is likely your username on Travis. -travis_namespace: robertdebock - -# Documentation refers to Ansible Galaxy. this is likely your username on Galaxy. -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) - -# The full URL to your website. -author_website: "https://robertdebock.nl/" - +# A map that relates the `meta/main.yml` - `galaxy_info.platforms.name` to a name of a container. platform_image_mapping: Alpine: alpine Amazon: amazonlinux Archlinux: archlinux Debian: debian - EL: "{{ enterprise_linux | default('enterpriselinux') }}" + EL: enterpriselinux Fedora: fedora opensuse: opensuse Ubuntu: ubuntu +# A map that relates a container name to the URL of that container on Docker Hub. 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" + alpine: "https://hub.docker.com/repository/docker/{{ docker_namespace }}/alpine/general" + amazon: "https://hub.docker.com/repository/docker/{{ docker_namespace }}/amazonlinux/general" + archlinux: "https://hub.docker.com/repository/docker/{{ docker_namespace }}/archlinux/general" + debian: "https://hub.docker.com/repository/docker/{{ docker_namespace }}/debian/general" + el: "https://hub.docker.com/repository/docker/{{ docker_namespace }}/enterpriselinux/general" + fedora: "https://hub.docker.com/repository/docker/{{ docker_namespace }}/fedora/general" + opensuse: "https://hub.docker.com/repository/docker/{{ docker_namespace }}/opensuse/general" + ubuntu: "https://hub.docker.com/repository/docker/{{ docker_namespace }}/ubuntu/general" # This maps the Galaxy distribution and version to Docker images. +# A map that relates the `meta/main.yml` - `galaxy_info.platforms.versions` to the tag of the Docker container. distribution_version_mapping: Alpine: all: @@ -105,6 +85,7 @@ distribution_version_mapping: bionic: - bionic +# To schedule CI on different days of the month, this is a map that relates a letter to a day of the month. letter_day_mapping: a: 1 b: 2 @@ -143,6 +124,7 @@ letter_day_mapping: 8: 27 9: 27 +# To schedule CI on different hours of the day, this is a map that relates a letter to an hour of the day. letter_hour_mapping: a: 1 b: 2 @@ -181,6 +163,7 @@ letter_hour_mapping: 8: 23 9: 23 +# To schedule CI on different days of the month, this is a map that relates a letter to a minute of the hour. letter_minute_mapping: a: 1 b: 3 diff --git a/vars/vault.yml b/vars/vault.yml deleted file mode 100644 index 6a020b7..0000000 --- a/vars/vault.yml +++ /dev/null @@ -1,14 +0,0 @@ -$ANSIBLE_VAULT;1.1;AES256 -35626138373665613930386237633532396164326166376163316366366432393338303535303163 -6435353933333036376462376232366338616335356631310a633732336234386438303761666332 -33643039346337393637346535343966616237376532646561363765663639356138353766303239 -6333313664656339360a393362326563643366376531366563373363396530666138663431346261 -30333566626130363638333162623537316539656264393238656136336431366133636330393635 -61366365613938343063353631633466623466623634343062656233303663663166313836346432 -35386133356664393235373364343534306635326365346465623462376162396539646538613664 -33666562633565643732613637313730306465663730363263346665663064326363396164616165 -61323535346661633364643663623730623662373765663861323236613164623266663361653734 -62666439353333666333323432613439393336643536663237393734313234376532333532353339 -65616634616230613632326162313962373665396265343838333363623437353238633231356262 -33353131616565353065346131636133313833633539323832376262386438303333363763613039 -3235 diff --git a/workflows/shellcheck.yml b/workflows/shellcheck.yml new file mode 100644 index 0000000..158c92f --- /dev/null +++ b/workflows/shellcheck.yml @@ -0,0 +1,13 @@ +--- + +name: 'shellcheck' +on: + push: + +jobs: + shellcheck: + name: shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ludeeus/action-shellcheck@master diff --git a/workflows/yamllint.yml b/workflows/yamllint.yml new file mode 100644 index 0000000..741797e --- /dev/null +++ b/workflows/yamllint.yml @@ -0,0 +1,13 @@ +--- + +name: 'yamllint' +on: + push: + +jobs: + yamllint: + name: yamllint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: karancode/yamllint-github-action@master From 020363d107b8ccf75b1be678c07fc9cdc458e356 Mon Sep 17 00:00:00 2001 From: Robert de Bock Date: Thu, 23 Feb 2023 09:33:23 +0100 Subject: [PATCH 4/4] Let's help YAMLlint a bit. --- .yamllint | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .yamllint 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