initial commit
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Robert Kaussow 2020-05-19 10:18:29 +02:00
commit 3d736acfbd
24 changed files with 800 additions and 0 deletions

154
.drone.jsonnet Normal file
View File

@ -0,0 +1,154 @@
local PipelineLinting = {
kind: 'pipeline',
name: 'linting',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'ansible-later',
image: 'xoxys/ansible-later',
commands: [
'ansible-later',
],
},
],
trigger: {
ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'],
},
};
local PipelineDeployment(scenario='centos7') = {
kind: 'pipeline',
name: 'testing-' + scenario,
platform: {
os: 'linux',
arch: 'amd64',
},
concurrency: {
limit: 1,
},
workspace: {
base: '/drone/src',
path: '${DRONE_REPO_NAME}',
},
steps: [
{
name: 'ansible-molecule',
image: 'xoxys/molecule:3',
environment: {
DO_API_KEY: { from_secret: 'do_api_key' },
MOLECULE_CUSTOM_MODULES_REPO: 'https://gitea.rknet.org/ansible/custom_modules',
MOLECULE_CUSTOM_FILTERS_REPO: 'https://gitea.rknet.org/ansible/custom_filters',
},
commands: [
'molecule test -s' + scenario,
],
},
],
depends_on: [
'linting',
],
trigger: {
ref: ['refs/heads/master', 'refs/tags/**'],
},
};
local PipelineDocumentation = {
kind: 'pipeline',
name: 'documentation',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'generate',
image: 'xoxys/ansible-doctor',
environment: {
ANSIBLE_DOCTOR_LOG_LEVEL: 'INFO',
ANSIBLE_DOCTOR_FORCE_OVERWRITE: true,
ANSIBLE_DOCTOR_EXCLUDE_FILES: 'molecule/',
ANSIBLE_DOCTOR_TEMPLATE: 'hugo-book',
ANSIBLE_DOCTOR_ROLE_NAME: '${DRONE_REPO_NAME#*.}',
ANSIBLE_DOCTOR_OUTPUT_DIR: '_docs/',
},
},
{
name: 'publish',
image: 'plugins/gh-pages',
settings: {
remote_url: 'https://gitea.rknet.org/ansible/${DRONE_REPO_NAME}',
netrc_machine: 'gitea.rknet.org',
username: { from_secret: 'gitea_username' },
password: { from_secret: 'gitea_token' },
pages_directory: '_docs/',
target_branch: 'docs',
},
when: {
ref: ['refs/heads/master'],
},
},
{
name: 'trigger',
image: 'plugins/downstream',
settings: {
server: 'https://drone.rknet.org',
token: { from_secret: 'drone_token' },
fork: true,
repositories: [
'ansible/ansible-galaxy',
],
},
when: {
ref: ['refs/heads/master'],
},
},
],
trigger: {
ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'],
},
depends_on: [
'testing-centos7',
],
};
local PipelineNotification = {
kind: 'pipeline',
name: 'notification',
platform: {
os: 'linux',
arch: 'amd64',
},
clone: {
disable: true,
},
steps: [
{
name: 'matrix',
image: 'plugins/matrix',
settings: {
homeserver: { from_secret: 'matrix_homeserver' },
roomid: { from_secret: 'matrix_roomid' },
template: 'Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}',
username: { from_secret: 'matrix_username' },
password: { from_secret: 'matrix_password' },
},
},
],
depends_on: [
'documentation',
],
trigger: {
status: ['success', 'failure'],
ref: ['refs/heads/master', 'refs/tags/**'],
},
};
[
PipelineLinting,
PipelineDeployment(scenario='centos7'),
PipelineDocumentation,
PipelineNotification,
]

151
.drone.yml Normal file
View File

@ -0,0 +1,151 @@
---
kind: pipeline
name: linting
platform:
os: linux
arch: amd64
steps:
- name: ansible-later
image: xoxys/ansible-later
commands:
- ansible-later
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
---
kind: pipeline
name: testing-centos7
platform:
os: linux
arch: amd64
concurrency:
limit: 1
workspace:
base: /drone/src
path: ${DRONE_REPO_NAME}
steps:
- name: ansible-molecule
image: xoxys/molecule:3
commands:
- molecule test -scentos7
environment:
DO_API_KEY:
from_secret: do_api_key
MOLECULE_CUSTOM_FILTERS_REPO: https://gitea.rknet.org/ansible/custom_filters
MOLECULE_CUSTOM_MODULES_REPO: https://gitea.rknet.org/ansible/custom_modules
trigger:
ref:
- refs/heads/master
- refs/tags/**
depends_on:
- linting
---
kind: pipeline
name: documentation
platform:
os: linux
arch: amd64
steps:
- name: generate
image: xoxys/ansible-doctor
environment:
ANSIBLE_DOCTOR_EXCLUDE_FILES: molecule/
ANSIBLE_DOCTOR_FORCE_OVERWRITE: true
ANSIBLE_DOCTOR_LOG_LEVEL: INFO
ANSIBLE_DOCTOR_OUTPUT_DIR: _docs/
ANSIBLE_DOCTOR_ROLE_NAME: ${DRONE_REPO_NAME#*.}
ANSIBLE_DOCTOR_TEMPLATE: hugo-book
- name: publish
image: plugins/gh-pages
settings:
netrc_machine: gitea.rknet.org
pages_directory: _docs/
password:
from_secret: gitea_token
remote_url: https://gitea.rknet.org/ansible/${DRONE_REPO_NAME}
target_branch: docs
username:
from_secret: gitea_username
when:
ref:
- refs/heads/master
- name: trigger
image: plugins/downstream
settings:
fork: true
repositories:
- ansible/ansible-galaxy
server: https://drone.rknet.org
token:
from_secret: drone_token
when:
ref:
- refs/heads/master
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
depends_on:
- testing-centos7
---
kind: pipeline
name: notification
platform:
os: linux
arch: amd64
clone:
disable: true
steps:
- name: matrix
image: plugins/matrix
settings:
homeserver:
from_secret: matrix_homeserver
password:
from_secret: matrix_password
roomid:
from_secret: matrix_roomid
template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}"
username:
from_secret: matrix_username
trigger:
ref:
- refs/heads/master
- refs/tags/**
status:
- success
- failure
depends_on:
- documentation
---
kind: signature
hmac: 00f1285cfd2cb8c7b2c5d4a8175e24d3b9b71e9faa7db6abe6f1986756349d1f
...

5
.flake8 Normal file
View File

@ -0,0 +1,5 @@
[flake8]
ignore = D101, D102, D103, D105, D107, E402, W503
max-line-length = 99
inline-quotes = double
exclude = .git,.tox,__pycache__,build,dist,tests,*.pyc,*.egg-info,.cache,.eggs,env*

11
.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
# ---> Ansible
*.retry
plugins
library
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

18
.later.yml Normal file
View File

@ -0,0 +1,18 @@
---
ansible:
custom_modules:
- iptables_raw
- openssl_pkcs12
- proxmox_kvm2
- ucr
- yum_versionlock
rules:
exclude_files:
- molecule/
- "LICENSE*"
- "**/*.md"
- "**/*.ini"
exclude_filter:
- LINT0009

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Robert Kaussow <mail@geeklabor.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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

14
README.md Normal file
View File

@ -0,0 +1,14 @@
# xoxys.minio
[![Build Status](https://img.shields.io/drone/build/ansible/xoxys.minio?logo=drone&server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/ansible/xoxys.minio)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?label=license)](LICENSE)
You can find the full documentation at [https://galaxy.geekdocs.de](https://galaxy.geekdocs.de/roles/cloud/minio/).
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Maintainers and Contributors
[Robert Kaussow](https://gitea.rknet.org/xoxys)

27
defaults/main.yml Normal file
View File

@ -0,0 +1,27 @@
---
minio_version: 2020-05-06T23-23-25Z
minio_user: "minio"
minio_user_home: "/home/{{ minio_user }}"
minio_group: "{{ minio_user }}"
minio_extra_groups: []
minio_packages: []
minio_base_dir: /opt/minio
minio_bin_dir: /opt/minio/bin
minio_data_dirs:
- /opt/minio/data
minio_bind_ip: 127.0.0.1
minio_bind_port: 61000
# Additional environment variables to be set in minio server environment
minio_server_env_extra: []
# Additional Minio server CLI options
minio_server_opts: []
# Minio access and secret keys
minio_access_key: ""
minio_secret_key: ""

10
handlers/main.yml Normal file
View File

@ -0,0 +1,10 @@
---
- name: Restart Minio service
systemd:
name: minio
state: restarted
daemon_reload: yes
enabled: yes
listen: __minio_restart
become: True
become_user: root

21
meta/main.yml Normal file
View File

@ -0,0 +1,21 @@
# Standards: 0.1
---
galaxy_info:
# @meta author:value: [Robert Kaussow](https://gitea.rknet.org/xoxys)
author: "Robert Kaussow <mail@geeklabor.de>"
# @meta description: >
# [![Source Code](https://img.shields.io/badge/gitea-source%20code-blue?logo=gitea&logoColor=white)](https://gitea.rknet.org/ansible/xoxys.minio)
# [![Build Status](https://img.shields.io/drone/build/ansible/xoxys.minio?logo=drone&server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/ansible/xoxys.minio)
# [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?label=license)](LICENSE)
#
# Setup Minio S3 server
# @end
description: Setup Minio S3 server
license: MIT
min_ansible_version: 2.8
platforms:
- name: EL
versions:
- 7
galaxy_tags:
dependencies: []

View File

@ -0,0 +1,10 @@
---
- name: Converge
hosts: all
vars:
minio_server_env_extra:
- name: minio_prometheus_auth_type
value: "public"
roles:
- role: "xoxys.minio"

View File

@ -0,0 +1,89 @@
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
vars:
ssh_user: root
ssh_port: 22
keypair_name: molecule_key
keypair_path: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/ssh_key"
tasks:
- name: Create local keypair
user:
name: "{{ lookup('env', 'USER') }}"
generate_ssh_key: true
ssh_key_file: "{{ keypair_path }}"
register: local_keypair
- name: Create remote keypair
digital_ocean_sshkey:
name: "{{ keypair_name }}"
ssh_pub_key: "{{ local_keypair.ssh_public_key }}"
state: present
register: remote_keypair
- name: Create molecule instance(s)
digital_ocean_droplet:
name: "{{ item.name }}"
unique_name: true
region: "{{ item.region_id }}"
image: "{{ item.image_id }}"
size: "{{ item.size_id }}"
ssh_keys: "{{ remote_keypair.data.ssh_key.id }}"
wait: true
wait_timeout: 300
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: digitalocean_jobs
until: digitalocean_jobs.finished
retries: 300
loop: "{{ server.results }}"
# Mandatory configuration for Molecule to function.
- name: Populate instance config dict
set_fact:
instance_conf_dict: {
'instance': "{{ item.data.droplet.name }}",
'address': "{{ item.data.ip_address }}",
'user': "{{ ssh_user }}",
'port': "{{ ssh_port }}",
'identity_file': "{{ keypair_path }}",
'droplet_id': "{{ item.data.droplet.id }}",
'ssh_key_id': "{{ remote_keypair.data.ssh_key.id }}",
}
loop: "{{ digitalocean_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: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
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
timeout: 320
loop: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"

View File

@ -0,0 +1,56 @@
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
tasks:
- block:
- name: Populate instance config
set_fact:
instance_conf: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"
skip_instances: false
rescue:
- name: Populate instance config when file missing
set_fact:
instance_conf: {}
skip_instances: true
- name: Destroy molecule instance(s)
digital_ocean_droplet:
name: "{{ item.instance }}"
id: "{{ item.droplet_id }}"
state: absent
register: server
loop: "{{ instance_conf | flatten(levels=1) }}"
when: not skip_instances
async: 7200
poll: 0
- name: Wait for instance(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: digitalocean_jobs
until: digitalocean_jobs.finished
retries: 300
loop: "{{ server.results }}"
- name: Delete remote keypair
digital_ocean_sshkey:
fingerprint: "{{ item.ssh_key_id }}"
state: absent
loop: "{{ instance_conf | flatten(levels=1) }}"
# Mandatory configuration for Molecule to function.
- name: Populate instance config
set_fact:
instance_conf: {}
- name: Dump instance config
copy:
content: "{{ instance_conf | molecule_to_yaml | molecule_header }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool

View File

@ -0,0 +1,16 @@
---
dependency:
name: galaxy
driver:
name: delegated
platforms:
- name: centos7-minio
region_id: fra1
image_id: centos-7-x64
size_id: s-1vcpu-1gb
lint: |
flake8 --max-line-length=99
provisioner:
name: ansible
verifier:
name: testinfra

View File

@ -0,0 +1,9 @@
---
- name: Prepare
hosts: all
gather_facts: false
tasks:
- name: Install python for Ansible
raw: test -e /usr/bin/python || (dnf -y install python3 && alternatives --set python /usr/bin/python3)
become: true
changed_when: false

View File

@ -0,0 +1,32 @@
import os
import testinfra.utils.ansible_runner
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_minio_running_and_enabled(host):
minio = host.service("minio")
assert minio.is_running
assert minio.is_enabled
def test_minio_socket(host):
# Verify the socket is listening for HTTP traffic
assert host.socket("tcp://127.0.0.1:61000").is_listening
def test_minio_conn_error(host):
code = int(
host.run(
"curl -s -w '%{http_code}' http://localhost:61000/minio/health/live -o /dev/null"
).stdout)
body = host.run(
"curl -sX GET http://localhost:61000/minio/prometheus/metrics").stdout
assert code == 200
assert "minio_version_info" in body

1
molecule/default Symbolic link
View File

@ -0,0 +1 @@
centos7

3
molecule/pytest.ini Normal file
View File

@ -0,0 +1,3 @@
[pytest]
filterwarnings =
ignore::DeprecationWarning

3
tasks/main.yml Normal file
View File

@ -0,0 +1,3 @@
---
- include_tasks: prepare.yml
- include_tasks: setup.yml

34
tasks/prepare.yml Normal file
View File

@ -0,0 +1,34 @@
---
- block:
- name: Stat minio-latest
stat:
path: "{{ minio_base_dir }}/minio-latest"
register: minio_installed
- name: Get running version
shell: "{{ minio_base_dir }}/minio-latest -v | sed -nre 's/^[^0-9]*(([0-9]+\\.)*[0-9]+(-\\S*)).*/\\1/p'"
register: minio_current
changed_when: False
when: minio_installed.stat.exists
- name: Create group '{{ minio_group }}'
group:
name: "{{ minio_group }}"
state: present
- name: Create user '{{ minio_user }}'
user:
comment: minio
name: "{{ minio_user }}"
home: "{{ minio_user_home }}"
group: "{{ minio_group }}"
groups: "{{ minio_extra_groups | join(',') }}"
- name: Install dependencies
package:
name: "{{ item }}"
state: present
loop:
- "{{ minio_packages }}"
become: True
become_user: root

57
tasks/setup.yml Normal file
View File

@ -0,0 +1,57 @@
---
- name: Prepare base folder
file:
path: "{{ minio_base_dir }}"
state: directory
owner: "{{ minio_user }}"
group: "{{ minio_user }}"
mode: 0750
become: True
become_user: root
- name: Prepare folder structure
file:
path: "{{ item }}"
state: directory
loop: "{{ __minio_dirs + minio_data_dirs }}"
become: True
become_user: "{{ minio_user }}"
- block:
- name: Download Minio binary
get_url:
url: "https://dl.min.io/server/minio/release/linux-amd64/archive/minio.RELEASE.{{ minio_version }}"
dest: "{{ minio_bin_dir }}/minio.{{ minio_version }}"
mode: 0750
- name: Link Version {{ minio_version }} to latest
file:
src: "{{ minio_bin_dir }}/minio.{{ minio_version }}"
dest: "{{ minio_base_dir }}/minio-latest"
state: link
notify: __minio_restart
become: True
become_user: "{{ minio_user }}"
when: not minio_installed.stat.exists or ((minio_version | to_datetime('%Y-%m-%dT%H-%M-%SZ') - minio_current.stdout | to_datetime('%Y-%m-%dT%H-%M-%SZ')).total_seconds() / 3600) | int > 0
- block:
- name: Copy sysconfig file
template:
src: "etc/sysconfig/minio.j2"
dest: "{{ __minio_sysconfig }}"
notify: __minio_restart
- name: Copy systemd unit file
template:
src: "etc/systemd/system/minio.service.j2"
dest: "/etc/systemd/system/minio.service"
notify: __minio_restart
- name: Ensure minio service is up and running
systemd:
name: minio
daemon_reload: yes
enabled: yes
state: started
become: True
become_user: root

View File

@ -0,0 +1,15 @@
#jinja2: lstrip_blocks: True
{{ ansible_managed | comment }}
MINIO_VOLUMES="{{ minio_data_dirs | join(' ') }}"
MINIO_OPTS="--address {{ minio_bind_ip }}:{{ minio_bind_port }} {{ minio_server_opts | join(' ') }}"
{% if minio_access_key %}
MINIO_ACCESS_KEY="{{ minio_access_key }}"
{% endif %}
{% if minio_secret_key %}
MINIO_SECRET_KEY="{{ minio_secret_key }}"
{% endif %}
{% for extra in minio_server_env_extra %}
{{ extra.name | upper }}={{ extra.value }}
{% endfor %}

View File

@ -0,0 +1,39 @@
#jinja2: lstrip_blocks: True
{{ ansible_managed | comment }}
[Unit]
Description=Minio S3 Object Storage
Documentation=https://docs.minio.io
Wants=network-online.target
After=network-online.target
After=syslog.target
# Avoid noisy crashloops
StartLimitIntervalSec=60
StartLimitBurst=5
[Service]
WorkingDirectory={{ minio_base_dir }}
User={{ minio_user }}
Group={{ minio_group }}
PermissionsStartOnly=true
EnvironmentFile={{ __minio_sysconfig }}
ExecStartPre=/bin/bash -c "[ -n \"${MINIO_VOLUMES}\" ] || echo \"Variable MINIO_VOLUMES not set in {{ __minio_sysconfig }}\""
ExecStart={{ minio_base_dir }}/minio-latest server $MINIO_OPTS $MINIO_VOLUMES
Restart=always
StandardOutput=journal
StandardError=inherit
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
TimeoutStopSec=0
KillSignal=SIGTERM
SendSIGKILL=no
SuccessExitStatus=0
[Install]
WantedBy=multi-user.target

4
vars/main.yml Normal file
View File

@ -0,0 +1,4 @@
---
__minio_sysconfig: /etc/sysconfig/minio
__minio_dirs:
- "{{ minio_bin_dir }}"