Skip to content

Commit

Permalink
add molecule github actions (#95)
Browse files Browse the repository at this point in the history
* added molecule and ansible-lint github actions

Co-authored-by: Lane Jennison <lane@lane-fu.com>
Co-authored-by: Bas Meijer <bas.meijer@me.com>
Co-authored-by: Michal Muransky <mike.muransky@gmail.com>
Co-authored-by: adawalli <adam.wallis@gmail.com>
Co-authored-by: Sebastian Gumprich <rndmh3ro@users.noreply.github.com>
Co-authored-by: John Adams <john@hexb.it>
Co-authored-by: jebas <jeff.l.baskin@gmail.com>
Co-authored-by: Michal Muransky <michal.muransky@pan-net.eu>
Co-authored-by: beechesII <grau.christopher@googlemail.com>
  • Loading branch information
10 people authored Jan 3, 2024
1 parent 92d4e33 commit 82c3714
Show file tree
Hide file tree
Showing 48 changed files with 470 additions and 50 deletions.
15 changes: 15 additions & 0 deletions .config/ansible-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
# .ansible-lint
exclude_paths:
- .cache/ # implicit unless exclude_paths is defined in config
- .yamllint
- molecule/
- tests/
- .github/

# install collection dependencies
offline: false

# skip these linting stuff
skip_list:
- '106'
14 changes: 14 additions & 0 deletions .github/workflows/ansible-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: ansible-lint
on:
pull_request:
branches: ["main", "master", "stable", "release/v*"]
jobs:
build:
name: Ansible Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Run ansible-lint
uses: ansible/ansible-lint@v6.22.1
40 changes: 40 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: molecule
on:
pull_request:
branches: ["main", "master", "stable", "release/v*"]

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 4
matrix:
scenario:
- centos-7
- centos-8-stream
- centos-9-stream
- debian-10
- debian-11
- debian-12
- fedora-38
- fedora-39
# - oraclelinux-7
- oraclelinux-8
- oraclelinux-9
- ubuntu-20.04
- ubuntu-22.04
- ubuntu-23.04

steps:
- uses: actions/checkout@v2
with:
path: "${{ github.repository }}"

- name: Molecule
uses: gofrolist/molecule-action@v2
with:
molecule_working_dir: "${{ github.repository }}"
molecule_options: --base-config molecule/_shared/base.yml
molecule_args: --scenario-name ${{ matrix.scenario }}
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

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
document-start: disable
8 changes: 5 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ os_supported_matrix:
RedHat:
min_version: '6'
CentOS:
min_version: '6'
min_version: '7'
Fedora:
min_version: ''
Amazon:
min_version: ''
# Debian based
OracleLinux:
min_version: '8'
Debian:
min_version: '8.2'
min_version: '10'
Ubuntu:
min_version: '13.04'
min_version: '20.04'
VMware Photon OS:
min_version: '4'

Expand Down
6 changes: 4 additions & 2 deletions examples/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
hosts: nomad_instances
become: yes
become_user: root
roles:
- { role: brianshumate.nomad }

tasks:
- name: nomad role
include_role:
name: ansible-community.nomad

- name: Start nomad
service: name=nomad state=started enabled=yes
3 changes: 2 additions & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ galaxy_info:
company: Brian Shumate
license: BSD
min_ansible_version: 2.5

role_name: ansible_nomad
namespace: brianshumate
platforms:
- name: Archlinux
versions:
Expand Down
29 changes: 29 additions & 0 deletions molecule/_shared/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Molecule managed

{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}

{% if item.env is defined %}
{% for var, value in item.env.items() %}
{% if value %}
ENV {{ var }} {{ value }}
{% endif %}
{% endfor %}
{% endif %}

RUN if [ $(command -v apt-get) ]; then \
if grep -q "Debian GNU/Linux 10" /etc/os-release; then \
apt-get update && apt-get install -y systemd python sudo bash ca-certificates iproute2 python-apt-common && apt-get clean; \
elif grep -q "Debian GNU/Linux 11" /etc/os-release; then \
apt-get update && apt-get install -y systemd python sudo bash ca-certificates iproute2 python-apt-common && apt-get clean; \
else \
apt-get update && apt-get install -y systemd python3 sudo bash ca-certificates iproute2 python3-apt && apt-get clean; \
fi \
elif [ $(command -v dnf) ]; then \
dnf makecache && dnf --assumeyes install systemd python3 sudo bash iproute && dnf clean all; \
elif [ $(command -v yum) ]; then \
yum makecache fast && yum install -y systemd python sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
fi
34 changes: 34 additions & 0 deletions molecule/_shared/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
scenario:
test_sequence:
- dependency
- syntax
- create
- prepare
- converge
- verify
- destroy
dependency:
name: galaxy
driver:
name: docker
provisioner:
name: ansible
config_options:
defaults:
deprecation_warnings: false
callback_whitelist: timer,profile_tasks
fact_caching: jsonfile
fact_caching_connection: ./cache
forks: 100
connection:
pipelining: true
playbooks:
prepare: ../_shared/prepare.yml
converge: ../_shared/converge.yml
inventory:
group_vars:
nomad_instances:
nomad_node_role: both
verifier:
name: ansible
9 changes: 9 additions & 0 deletions molecule/_shared/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
roles:
- role: ansible-nomad

vars:
# TODO: Probably we need to install syslog-ng/rsyslog first
nomad_syslog_enable: False
15 changes: 15 additions & 0 deletions molecule/_shared/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Prepare
hosts: localhost
connection: local

tasks:
- name: Install OS packages
package:
name: unzip
become: true

- name: Install netaddr dependency on controlling host
pip:
name: netaddr
become: false
59 changes: 59 additions & 0 deletions molecule/_shared/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
- name: Verify
hosts: all
tasks:

- name: Verify that /etc/nomad.d/base.hcl exists
ansible.builtin.file:
path: /etc/nomad.d/base.hcl
state: file
register: result_nomad_base_hcl

- name: Validate that /etc/nomad.d/base.hcl exists
ansible.builtin.assert:
that:
- result_nomad_base_hcl.state == 'file'
- result_nomad_base_hcl.owner == 'root'
- result_nomad_base_hcl.group == 'root'
- result_nomad_base_hcl.mode == '0644'

- name: Verify that /etc/nomad.d/client.hcl exists
ansible.builtin.file:
path: /etc/nomad.d/client.hcl
state: file
register: result_nomad_client_hcl

- name: Validate that /etc/nomad.d/client.hcl exists
ansible.builtin.assert:
that:
- result_nomad_client_hcl.state == 'file'
- result_nomad_client_hcl.owner == 'root'
- result_nomad_client_hcl.group == 'root'
- result_nomad_client_hcl.mode == '0644'

- name: Verify that /etc/nomad.d/server.hcl exists
ansible.builtin.file:
path: /etc/nomad.d/server.hcl
state: file
register: result_nomad_server_hcl

- name: Validate that /etc/nomad.d/server.hcl exists
ansible.builtin.assert:
that:
- result_nomad_server_hcl.state == 'file'
- result_nomad_server_hcl.owner == 'root'
- result_nomad_server_hcl.group == 'root'
- result_nomad_server_hcl.mode == '0644'

- name: Verify that serivce nomad is running
ansible.builtin.service:
name: nomad
state: started
register: result_nomad_service

- name: Validate that serivce nomad is running
ansible.builtin.assert:
that:
- result_nomad_service.state == 'started'
- result_nomad_service.changed == false
- result_nomad_service.name == 'nomad'
14 changes: 14 additions & 0 deletions molecule/centos-7/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
platforms:
- name: centos-7
groups:
- nomad_instances
image: dokken/centos-7
dockerfile: ../_shared/Dockerfile.j2
capabilities:
- SYS_ADMIN
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
privileged: true
command: /usr/lib/systemd/systemd
1 change: 1 addition & 0 deletions molecule/centos-7/verify.yml
14 changes: 14 additions & 0 deletions molecule/centos-8-stream/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
platforms:
- name: centos-stream-8
groups:
- nomad_instances
image: dokken/centos-stream-8
dockerfile: ../_shared/Dockerfile.j2
capabilities:
- SYS_ADMIN
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
privileged: true
command: /usr/lib/systemd/systemd
1 change: 1 addition & 0 deletions molecule/centos-8-stream/verify.yml
14 changes: 14 additions & 0 deletions molecule/centos-9-stream/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
platforms:
- name: centos-stream-9
groups:
- nomad_instances
image: dokken/centos-stream-9
dockerfile: ../_shared/Dockerfile.j2
capabilities:
- SYS_ADMIN
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
privileged: true
command: /usr/lib/systemd/systemd
1 change: 1 addition & 0 deletions molecule/centos-9-stream/verify.yml
14 changes: 14 additions & 0 deletions molecule/debian-10/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
platforms:
- name: debian-10
groups:
- nomad_instances
image: dokken/debian-10
dockerfile: ../_shared/Dockerfile.j2
capabilities:
- SYS_ADMIN
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
privileged: true
command: /bin/systemd
1 change: 1 addition & 0 deletions molecule/debian-10/verify.yml
14 changes: 14 additions & 0 deletions molecule/debian-11/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
platforms:
- name: debian-11
groups:
- nomad_instances
image: dokken/debian-11
dockerfile: ../_shared/Dockerfile.j2
capabilities:
- SYS_ADMIN
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
privileged: true
command: /bin/systemd
Loading

0 comments on commit 82c3714

Please sign in to comment.