Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role and test infrastructure #1

Merged
merged 18 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .ansible-lint-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file contains ignores rule violations for ansible-lint
meta/main.yml schema[meta]
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
exclude = .venv/,.tox/,dist/,build/,doc/,.eggs/,molecule/provisioner/ansible/plugins/libraries/goss.py
format = pylint
39 changes: 39 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: lint

on:

pull_request:
branches:
- master

defaults:

run:
working-directory: 'nephelaiio.mongos'

jobs:

lint:

name: lint
runs-on: ubuntu-latest
steps:
- name: Check out the codebase
uses: actions/checkout@v4
with:
path: 'nephelaiio.mongos'

- name: Set up python 3
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Update ubuntu repositories
run: sudo apt-get update

- name: Install make
run: sudo apt-get install -y make

- name: Lint code
run: make lint
64 changes: 64 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
name: molecule

on:

pull_request:
branches:
- master
schedule:
- cron: "0 5 * * 5"

defaults:

run:
working-directory: 'nephelaiio.mongos'

jobs:

molecule:

name: molecule
runs-on: ubuntu-latest
strategy:
matrix:
scenario:
- name: default
image:
- name: ubuntu2204
command: /lib/systemd/systemd
- name: ubuntu2004
command: /lib/systemd/systemd
- name: debian11
command: /lib/systemd/systemd
steps:
- name: Check out the codebase
uses: actions/checkout@v4
with:
path: 'nephelaiio.mongos'

- name: Set up python 3
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Update ubuntu repositories
run: sudo apt-get update

- name: Install make
run: sudo apt-get install -y make

- name: Install dependencies
run: make install

- name: Debug test environment
run: make debug

- name: Run molecule tests.
run: make test
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_DOCKER_IMAGE: ${{ matrix.image.name }}
MOLECULE_DOCKER_COMMAND: ${{ matrix.image.command }}
MOLECULE_SCENARIO: ${{ matrix.scenario.name }}
49 changes: 49 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
# This workflow requires a GALAXY_API_KEY secret present in the GitHub
# repository or organization.
#
# See: https://github.com/marketplace/actions/publish-ansible-role-to-galaxy
# See: https://github.com/ansible/galaxy/issues/46

name: Release
on:
push:
tags:
- "*"

defaults:

run:
working-directory: 'nephelaiio.mongos'

jobs:

release:

name: Release
runs-on: ubuntu-latest
steps:
- name: Check out the codebase.
uses: actions/checkout@v4
with:
path: 'nephelaiio.mongos'

- name: Set up Python 3
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Update ubuntu repositories
run: sudo apt-get update

- name: Install make
run: sudo apt-get install -y make

- name: Install dependencies
run: make install

- name: Trigger a new import on galaxy
run: make publish
env:
GALAXY_API_KEY: "${{ secrets.GALAXY_API_KEY }}"
GITHUB_REPOSITORY: "${{ github.repository }}"
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.swp
.molecule/
.cache/
__pycache__/
Gemfile.lock
**/.ropeproject
playbook.retry
7 changes: 7 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fileignoreconfig:
- filename: poetry.lock
ignore_detectors: [filecontent]
- filename: .github/workflows/release.yml
ignore_detectors: [filecontent]
- filename: templates/systemd.service.j2
ignore_detectors: [filecontent]
12 changes: 12 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
extends: default

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
line-length: disable
truthy: disable
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Copyright (c) 2023 Ted Cook


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 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.
55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.PHONY: all ${MAKECMDGOALS}

MOLECULE_SCENARIO ?= default
MOLECULE_DOCKER_IMAGE ?= ubuntu2004
GALAXY_API_KEY ?=
GITHUB_REPOSITORY ?= $$(git config --get remote.origin.url | cut -d: -f 2 | cut -d. -f 1)
GITHUB_ORG = $$(echo ${GITHUB_REPOSITORY} | cut -d/ -f 1)
GITHUB_REPO = $$(echo ${GITHUB_REPOSITORY} | cut -d/ -f 2)
REQUIREMENTS = requirements.yml

all: install version lint test

test: lint
poetry run molecule test -s ${MOLECULE_SCENARIO}

install:
@type poetry >/dev/null || pip3 install poetry
@poetry install

lint: install
poetry run yamllint .
poetry run ansible-lint .
poetry run molecule syntax

roles:
[ -f ${REQUIREMENTS} ] && yq '.$@[] | .name' -r < ${REQUIREMENTS} \
| xargs -L1 poetry run ansible-galaxy role install --force || exit 0

collections:
[ -f ${REQUIREMENTS} ] && yq '.$@[]' -r < ${REQUIREMENTS} \
| xargs -L1 echo poetry run ansible-galaxy -vvv collection install --force || exit 0

requirements: roles collections

dependency create prepare converge idempotence side-effect verify destroy login reset:
MOLECULE_DOCKER_IMAGE=${MOLECULE_DOCKER_IMAGE} poetry run molecule $@ -s ${MOLECULE_SCENARIO}

ignore:
poetry run ansible-lint --generate-ignore

clean: destroy reset
@poetry env remove $$(which python) >/dev/null 2>&1 || exit 0

publish:
@echo publishing repository ${GITHUB_REPOSITORY}
@echo GITHUB_ORGANIZATION=${GITHUB_ORG}
@echo GITHUB_REPOSITORY=${GITHUB_REPO}
@poetry run ansible-galaxy role import \
--api-key ${GALAXY_API_KEY} ${GITHUB_ORG} ${GITHUB_REPO}

version:
@poetry run molecule --version

debug: version
@poetry export --dev --without-hashes
3 changes: 3 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[default]
local_tmp=/tmp
remote_tmp=/tmp
19 changes: 19 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
mongos_package_name:
- mongodb-org-server
- mongodb-org-mongos
- mongodb-mongosh
- pkg-config
mongos_package_state: present
mongos_service_name: mongos
mongos_service_port: 27017
mongos_service_state: started
mongos_service_enabled: "{{ mongos_service_state != 'stopped' }}"
mongos_config_file: /etc/mongos.yaml
mongos_storage_path: /var/lib/mongodb
mongos_replicaset_config_name: config
mongos_replicaset_config_port: 27017
mongos_replicaset_config_members: []
mongos_replicaset_shards: []
mongos_user: mongodb
mongos_group: mongodb
11 changes: 11 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Reload systemd daemons
ansible.builtin.systemd:
daemon_reload: true
listen: daemon_reload

- name: Restart mongos service
ansible.builtin.service:
name: "{{ mongos_service_name }}"
state: restarted
listen: daemon_restart
23 changes: 23 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
galaxy_info:
standalone: true
role_name: mongos
author: nephelaiio
description: An Ansible role to install and configure mongos
license: MIT
min_ansible_version: '2.15'
platforms:
- name: EL
versions:
- all
- name: Ubuntu
versions:
- all
- name: Debian
versions:
- all
galaxy_tags: ['mongos']

dependencies:
- role: nephelaiio.plugins
- role: nephelaiio.mongodb_repo
11 changes: 11 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Gather config host facts
hosts: config:shard

- name: Deploy mongodb mongos servers
hosts: mongos
become: true
roles:
- nephelaiio.mongos
vars:
mongos_replicaset_config_members: "{{ groups['config'] | map('extract', hostvars, ['ansible_default_ipv4', 'address']) }}"
Loading