Let's Marie Kondo.
This commit is contained in:
parent
7bd953b13d
commit
a0ca7acced
|
|
@ -1,2 +0,0 @@
|
|||
*.swp
|
||||
secure.yml
|
||||
15
.yamllint
15
.yamllint
|
|
@ -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
|
||||
|
|
@ -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
|
||||
```
|
||||
108
README.md
108
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
|
||||
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
[defaults]
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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/"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
96
github.yml
96
github.yml
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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 }}"
|
||||
128
gitlab.yml
128
gitlab.yml
|
|
@ -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
|
||||
24
indexer.sh
24
indexer.sh
|
|
@ -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="[](https://github.com/robertdebock/${rolename}/actions)"
|
||||
gitlab="[](https://gitlab.com/robertdebock/${rolename})"
|
||||
version="[](https://github.com/robertdebock/${rolename}/releases)"
|
||||
|
||||
# Print the line of one role.
|
||||
echo "|${galaxy}|${github}|${gitlab}|${version}|"
|
||||
|
||||
done
|
||||
|
|
@ -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 %}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
$ANSIBLE_VAULT;1.1;AES256
|
||||
35626138373665613930386237633532396164326166376163316366366432393338303535303163
|
||||
6435353933333036376462376232366338616335356631310a633732336234386438303761666332
|
||||
33643039346337393637346535343966616237376532646561363765663639356138353766303239
|
||||
6333313664656339360a393362326563643366376531366563373363396530666138663431346261
|
||||
30333566626130363638333162623537316539656264393238656136336431366133636330393635
|
||||
61366365613938343063353631633466623466623634343062656233303663663166313836346432
|
||||
35386133356664393235373364343534306635326365346465623462376162396539646538613664
|
||||
33666562633565643732613637313730306465663730363263346665663064326363396164616165
|
||||
61323535346661633364643663623730623662373765663861323236613164623266663361653734
|
||||
62666439353333666333323432613439393336643536663237393734313234376532333532353339
|
||||
65616634616230613632326162313962373665396265343838333363623437353238633231356262
|
||||
33353131616565353065346131636133313833633539323832376262386438303333363763613039
|
||||
3235
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue