Compare commits

..

2 Commits

Author SHA1 Message Date
bd4ddf6461
fix dependencies
Some checks failed
continuous-integration/drone/pr Build is failing
2021-10-03 17:48:24 +02:00
6ccbded4ee
feat: add test for Rocky Linux 8
Some checks failed
continuous-integration/drone/pr Build is failing
2021-10-03 16:32:56 +02:00
17 changed files with 338 additions and 36 deletions

View File

@ -15,7 +15,7 @@ local PipelineLinting = {
},
{
name: 'python-format',
image: 'python:3.11',
image: 'python:3.9',
environment: {
PY_COLORS: 1,
},
@ -26,7 +26,7 @@ local PipelineLinting = {
},
{
name: 'python-flake8',
image: 'python:3.11',
image: 'python:3.9',
environment: {
PY_COLORS: 1,
},
@ -37,7 +37,7 @@ local PipelineLinting = {
},
],
trigger: {
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'],
},
};
@ -58,7 +58,7 @@ local PipelineDeployment(scenario='centos7') = {
steps: [
{
name: 'ansible-molecule',
image: 'thegeeklab/molecule:4',
image: 'thegeeklab/molecule:3',
environment: {
HCLOUD_TOKEN: { from_secret: 'hcloud_token' },
},
@ -71,7 +71,7 @@ local PipelineDeployment(scenario='centos7') = {
'linting',
],
trigger: {
ref: ['refs/heads/main', 'refs/tags/**'],
ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'],
},
};
@ -107,15 +107,16 @@ local PipelineDocumentation = {
target_branch: 'docs',
},
when: {
ref: ['refs/heads/main'],
ref: ['refs/heads/master'],
},
},
],
trigger: {
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'],
},
depends_on: [
'testing-centos7',
'testing-rocky8',
],
};
@ -136,7 +137,7 @@ local PipelineNotification = {
settings: {
homeserver: { from_secret: 'matrix_homeserver' },
roomid: { from_secret: 'matrix_roomid' },
template: 'Status: **{{ .Build.Status }}**<br/> Build: [{{ .Repo.Owner }}/{{ .Repo.Name }}]({{ .Build.Link }}){{ if .Build.Branch }} ({{ .Build.Branch }}){{ end }} by {{ .Commit.Author }}<br/> Message: {{ .Commit.Message.Title }}',
template: 'Status: **{{ build.Status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.Link }}){{#if build.Branch}} ({{ build.Branch }}){{/if}} by {{ commit.Author }}<br/> Message: {{ commit.Message.Title }}',
username: { from_secret: 'matrix_username' },
password: { from_secret: 'matrix_password' },
},
@ -147,13 +148,14 @@ local PipelineNotification = {
],
trigger: {
status: ['success', 'failure'],
ref: ['refs/heads/main', 'refs/tags/**'],
ref: ['refs/heads/master', 'refs/tags/**'],
},
};
[
PipelineLinting,
PipelineDeployment(scenario='centos7'),
PipelineDeployment(scenario='rocky8'),
PipelineDocumentation,
PipelineNotification,
]

View File

@ -13,7 +13,7 @@ steps:
- ansible-later
- name: python-format
image: python:3.11
image: python:3.9
commands:
- pip install -qq yapf
- "[ -z \"$(find . -type f -name *.py)\" ] || (yapf -rd ./)"
@ -21,7 +21,7 @@ steps:
PY_COLORS: 1
- name: python-flake8
image: python:3.11
image: python:3.9
commands:
- pip install -qq flake8
- flake8
@ -30,7 +30,7 @@ steps:
trigger:
ref:
- refs/heads/main
- refs/heads/master
- refs/tags/**
- refs/pull/**
@ -51,7 +51,7 @@ workspace:
steps:
- name: ansible-molecule
image: thegeeklab/molecule:4
image: thegeeklab/molecule:3
commands:
- molecule test -s centos7
environment:
@ -60,8 +60,42 @@ steps:
trigger:
ref:
- refs/heads/main
- refs/heads/master
- refs/tags/**
- refs/pull/**
depends_on:
- linting
---
kind: pipeline
name: testing-rocky8
platform:
os: linux
arch: amd64
concurrency:
limit: 1
workspace:
base: /drone/src
path: ${DRONE_REPO_NAME}
steps:
- name: ansible-molecule
image: thegeeklab/molecule:3
commands:
- molecule test -s rocky8
environment:
HCLOUD_TOKEN:
from_secret: hcloud_token
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
depends_on:
- linting
@ -98,16 +132,17 @@ steps:
from_secret: gitea_username
when:
ref:
- refs/heads/main
- refs/heads/master
trigger:
ref:
- refs/heads/main
- refs/heads/master
- refs/tags/**
- refs/pull/**
depends_on:
- testing-centos7
- testing-rocky8
---
kind: pipeline
@ -130,13 +165,13 @@ steps:
from_secret: matrix_password
roomid:
from_secret: matrix_roomid
template: "Status: **{{ .Build.Status }}**<br/> Build: [{{ .Repo.Owner }}/{{ .Repo.Name }}]({{ .Build.Link }}){{ if .Build.Branch }} ({{ .Build.Branch }}){{ end }} by {{ .Commit.Author }}<br/> Message: {{ .Commit.Message.Title }}"
template: "Status: **{{ build.Status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.Link }}){{#if build.Branch}} ({{ build.Branch }}){{/if}} by {{ commit.Author }}<br/> Message: {{ commit.Message.Title }}"
username:
from_secret: matrix_username
trigger:
ref:
- refs/heads/main
- refs/heads/master
- refs/tags/**
status:
- success
@ -147,6 +182,6 @@ depends_on:
---
kind: signature
hmac: 598093270bf86829d2e02ae6081715a57bd7b7ac8df37d2c6afc47094506b5c4
hmac: 4ac5a2ce5639e39c7a80790467ba230ab5fe6b0548452e27e7f2b06163f75fa0
...

6
.gitignore vendored
View File

@ -1,13 +1,9 @@
# ---> Ansible
*.retry
plugins
filter/plugins/
library
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# ---> Docs
/_docs

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2022 Robert Kaussow <mail@thegeeklab.de>
Copyright (c) 2021 Robert Kaussow <mail@thegeeklab.de>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -3,7 +3,9 @@
[![Build Status](https://img.shields.io/drone/build/ansible/xoxys.renovate_bot?logo=drone&server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/ansible/xoxys.renovate_bot)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
Setup [renovate](https://github.com/renovatebot/renovate) universal dependency update tool. You can find the full documentation at [https://galaxy.geekdocs.de](https://galaxy.geekdocs.de/roles/cloud/renovate_bot/).
Setup a docker garbage collector.
You can find the full documentation at [https://galaxy.geekdocs.de](https://galaxy.geekdocs.de/roles/system/renovate_bot/).
## License

View File

@ -41,4 +41,3 @@ renovatebot_onboarding_config:
# password: "secure"
# @end
renovatebot_host_rules: []
renovate_binary_source: global

View File

@ -8,7 +8,7 @@ galaxy_info:
# @meta description: >
# [![Source Code](https://img.shields.io/badge/gitea-source%20code-blue?logo=gitea&logoColor=white)](https://gitea.rknet.org/ansible/xoxys.renovate_bot)
# [![Build Status](https://img.shields.io/drone/build/ansible/xoxys.renovate_bot?logo=drone&server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/ansible/xoxys.renovate_bot)
# [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://gitea.rknet.org/ansible/xoxys.renovate_bot/src/branch/main/LICENSE)
# [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://gitea.rknet.org/ansible/xoxys.renovate_bot/src/branch/master/LICENSE)
#
# Setup docker-renovate garbage collector. Keep docker hosts small.
# @end

View File

@ -6,8 +6,8 @@
vars:
dockerengine_packages_extra:
- epel-release
- python-pip
- python-virtualenv
- python3-pip
- python3-virtualenv
renovatebot_service_stopped: True
renovatebot_token: personal-access-token
renovatebot_repositories:

View File

@ -1 +1 @@
centos7
rocky8

View File

@ -7,9 +7,9 @@ roles:
- src: https://gitea.rknet.org/ansible/xoxys.python3.git
name: xoxys.python3
scm: git
version: main
version: master
- src: https://gitea.rknet.org/ansible/xoxys.docker_engine.git
name: xoxys.docker_engine
scm: git
version: main
version: master

View File

@ -0,0 +1,19 @@
---
- name: Converge
hosts: all
environment:
PYTHONPATH: /opt/python2/ansible-deps/lib/python2.7/site-packages
vars:
dockerengine_packages_extra:
- epel-release
- python3-pip
- python3-virtualenv
renovatebot_service_stopped: True
renovatebot_token: personal-access-token
renovatebot_repositories:
- ansible/test
- project/demo
roles:
- role: xoxys.docker_engine
- role: xoxys.renovate_bot

120
molecule/rocky8/create.yml Normal file
View File

@ -0,0 +1,120 @@
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
vars:
ssh_port: 22
ssh_user: root
ssh_path: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/ssh_key"
tasks:
- name: Create SSH key
user:
name: "{{ lookup('env', 'USER') }}"
generate_ssh_key: true
ssh_key_file: "{{ ssh_path }}"
force: true
register: generated_ssh_key
- name: Register the SSH key name
set_fact:
ssh_key_name: "molecule-generated-{{ 12345 | random | to_uuid }}"
- name: Register SSH key for test instance(s)
hcloud_ssh_key:
name: "{{ ssh_key_name }}"
public_key: "{{ generated_ssh_key.ssh_public_key }}"
state: present
- name: Create molecule instance(s)
hcloud_server:
name: "{{ item.name }}"
server_type: "{{ item.server_type }}"
ssh_keys:
- "{{ ssh_key_name }}"
image: "{{ item.image }}"
location: "{{ item.location | default(omit) }}"
datacenter: "{{ item.datacenter | default(omit) }}"
user_data: "{{ item.user_data | default(omit) }}"
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
state: present
register: server
loop: "{{ molecule_yml.platforms }}"
async: 7200
poll: 0
- name: Wait for instance(s) creation to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: hetzner_jobs
until: hetzner_jobs.finished
retries: 300
loop: "{{ server.results }}"
- name: Create volume(s)
hcloud_volume:
name: "{{ item.name }}"
server: "{{ item.name }}"
location: "{{ item.location | default(omit) }}"
size: "{{ item.volume_size | default(10) }}"
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
state: "present"
loop: "{{ molecule_yml.platforms }}"
when: item.volume | default(False) | bool
register: volumes
async: 7200
poll: 0
- name: Wait for volume(s) creation to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: hetzner_volumes
until: hetzner_volumes.finished
retries: 300
when: volumes.changed
loop: "{{ volumes.results }}"
# Mandatory configuration for Molecule to function.
- name: Populate instance config dict
set_fact:
instance_conf_dict:
{
"instance": "{{ item.hcloud_server.name }}",
"ssh_key_name": "{{ ssh_key_name }}",
"address": "{{ item.hcloud_server.ipv4_address }}",
"user": "{{ ssh_user }}",
"port": "{{ ssh_port }}",
"identity_file": "{{ ssh_path }}",
"volume": "{{ item.item.item.volume | default(False) | bool }}",
}
loop: "{{ hetzner_jobs.results }}"
register: instance_config_dict
when: server.changed | bool
- name: Convert instance config dict to a list
set_fact:
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
when: server.changed | bool
- name: Dump instance config
copy:
content: |
# Molecule managed
{{ instance_conf | to_nice_yaml(indent=2) }}
dest: "{{ molecule_instance_config }}"
when: server.changed | bool
- name: Wait for SSH
wait_for:
port: "{{ ssh_port }}"
host: "{{ item.address }}"
search_regex: SSH
delay: 10
loop: "{{ lookup('file', molecule_instance_config) | from_yaml }}"
- name: Wait for VM to settle down
pause:
seconds: 30

View File

@ -0,0 +1,78 @@
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
tasks:
- name: Check existing instance config file
stat:
path: "{{ molecule_instance_config }}"
register: cfg
- name: Populate the instance config
set_fact:
instance_conf: "{{ (lookup('file', molecule_instance_config) | from_yaml) if cfg.stat.exists else [] }}"
- name: Destroy molecule instance(s)
hcloud_server:
name: "{{ item.instance }}"
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
state: absent
register: server
loop: "{{ instance_conf }}"
async: 7200
poll: 0
- name: Wait for instance(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: hetzner_jobs
until: hetzner_jobs.finished
retries: 300
loop: "{{ server.results }}"
- pause:
seconds: 5
- name: Destroy volume(s)
hcloud_volume:
name: "{{ item.instance }}"
server: "{{ item.instance }}"
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
state: "absent"
register: volumes
loop: "{{ instance_conf }}"
when: item.volume | default(False) | bool
async: 7200
poll: 0
- name: Wait for volume(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: hetzner_volumes
until: hetzner_volumes.finished
retries: 300
when: volumes.changed
loop: "{{ volumes.results }}"
- name: Remove registered SSH key
hcloud_ssh_key:
name: "{{ instance_conf[0].ssh_key_name }}"
state: absent
when: (instance_conf | default([])) | length > 0
# Mandatory configuration for Molecule to function.
- name: Populate instance config
set_fact:
instance_conf: {}
- name: Dump instance config
copy:
content: |
# Molecule managed
{{ instance_conf | to_nice_yaml(indent=2) }}
dest: "{{ molecule_instance_config }}"
when: server.changed | bool

View File

@ -0,0 +1,24 @@
---
dependency:
name: galaxy
options:
role-file: molecule/requirements.yml
requirements-file: molecule/requirements.yml
env:
ANSIBLE_GALAXY_DISPLAY_PROGRESS: "false"
driver:
name: delegated
platforms:
- name: rocky8-renovatebot
image: rocky-8
server_type: cx11
lint: |
/usr/local/bin/flake8
provisioner:
name: ansible
env:
ANSIBLE_FILTER_PLUGINS: ${ANSIBLE_FILTER_PLUGINS:-./plugins/filter}
ANSIBLE_LIBRARY: ${ANSIBLE_LIBRARY:-./library}
log: False
verifier:
name: testinfra

View File

@ -0,0 +1,15 @@
---
- name: Prepare
hosts: all
gather_facts: false
tasks:
- name: Bootstrap python for Ansible
raw: |
command -v python3 python || (
(test -e /usr/bin/dnf && sudo dnf install -y python3) ||
(test -e /usr/bin/apt && (apt -y update && apt install -y python-minimal)) ||
(test -e /usr/bin/yum && sudo yum -y -qq install python3) ||
echo "Warning: Python not boostrapped due to unknown platform."
)
become: true
changed_when: false

View File

@ -0,0 +1,13 @@
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("all")
def test_renovate_running_and_enabled(host):
service = host.service("renovate.timer")
assert service.is_enabled

View File

@ -20,4 +20,3 @@ RENOVATE_REPOSITORIES={{ renovatebot_repositories | join(",") }}
{% endif %}
RENOVATE_ONBOARDING_CONFIG={{ renovatebot_onboarding_config | to_json }}
RENOVATE_HOST_RULES={{ renovatebot_host_rules | to_json }}
RENOVATE_BINARY_SOURCE={{ renovate_binary_source }}