Skip to content

Commit dd7208e

Browse files
authored
Add Ansible Molecule on Github Action (#39)
* 🙈 Ignore pycharm files * ➕ Add missing galaxy dependency * ⚗️ Add molecule and github workflow * 🚨 Fix linter * 🚀 Add deploy on galaxy * 🔥 Remove travis, replaced by github actions
1 parent c2ede87 commit dd7208e

File tree

16 files changed

+229
-61
lines changed

16 files changed

+229
-61
lines changed

.github/workflows/galaxy.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
3+
name: Deploy on Ansible Galaxy
4+
5+
'on':
6+
- push
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: checkout
13+
uses: actions/checkout@v2
14+
- name: galaxy
15+
uses: robertdebock/galaxy-action@1.2.0
16+
with:
17+
galaxy_api_key: ${{ secrets.galaxy_api_key }}

.github/workflows/molecule.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: Molecule
3+
4+
'on':
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
scenario:
17+
- debian-10
18+
- debian-11
19+
- debian-12
20+
- ubuntu-18.04
21+
- ubuntu-20.04
22+
- ubuntu-22.04
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
with:
28+
path: "${{ github.repository }}"
29+
30+
- name: Molecule
31+
uses: gofrolist/molecule-action@v2.3.19
32+
with:
33+
molecule_options: --base-config molecule/_shared/base.yml
34+
molecule_args: --scenario-name ${{ matrix.scenario }}
35+
molecule_working_dir: "HanXHX/ansible-debian-bootstrap"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.swp
33
*.retry
44
/ubuntu*.log
5+
/.idea

.travis.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Ansible Debian/Devuan/Ubuntu/Raspbian bootstrap
22
====================================================
33

4-
[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.debian_bootstrap-blue.svg)](https://galaxy.ansible.com/HanXHX/debian_bootstrap) [![Build Status](https://app.travis-ci.com/HanXHX/ansible-debian-bootstrap.svg?branch=master)](https://app.travis-ci.com/HanXHX/ansible-debian-bootstrap)
4+
[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.debian_bootstrap-blue.svg)](https://galaxy.ansible.com/HanXHX/debian_bootstrap) ![GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/hanxhx/ansible-debian-bootstrap/molecule.yml?branch=master)
55

66
This role bootstraps Debian/Devuan/Ubuntu/Raspbian hosts:
77

@@ -152,6 +152,34 @@ Due to Docker limitations, theses features are disabled:
152152
- Setting hostname
153153
- Configure sysctl
154154

155+
156+
How to develop and test this role
157+
---------------------------------
158+
159+
### Vagrant way
160+
161+
Install vagrant + virtualbox or docker
162+
163+
```commandline
164+
vagrant up debian-bullseye # with virtualbox
165+
vagrant up docker-debian-bullseye # with docker
166+
```
167+
168+
### Molecule way
169+
170+
Install:
171+
172+
```commandline
173+
pip install molecule molecule[docker]
174+
```
175+
176+
Run:
177+
178+
```commandline
179+
molecule -vv -c molecule/_shared/base.yml converge -s ubuntu-22.04
180+
```
181+
182+
155183
License
156184
-------
157185

molecule/_shared/Dockerfile.j2

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Molecule managed
2+
3+
{% if item.registry is defined %}
4+
FROM {{ item.registry.url }}/{{ item.image }}
5+
{% else %}
6+
FROM {{ item.image }}
7+
{% endif %}
8+
9+
{% if item.env is defined %}
10+
{% for var, value in item.env.items() %}
11+
{% if value %}
12+
ENV {{ var }} {{ value }}
13+
{% endif %}
14+
{% endfor %}
15+
{% endif %}
16+
17+
RUN apt-get update && \
18+
apt-get install -y python3 sudo bash ca-certificates iproute2 python-apt-common \
19+
&& apt-get clean

molecule/_shared/base.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
3+
scenario:
4+
test_sequence:
5+
- dependency
6+
- syntax
7+
- create
8+
- prepare
9+
- converge
10+
- idempotence
11+
- verify
12+
- destroy
13+
dependency:
14+
name: galaxy
15+
options:
16+
requirements-file: ../../requirements.yml
17+
driver:
18+
name: docker
19+
role_name_check: 1
20+
provisioner:
21+
name: ansible
22+
config_options:
23+
defaults:
24+
deprecation_warnings: false
25+
callback_whitelist: timer,profile_tasks
26+
fact_caching: jsonfile
27+
fact_caching_connection: ./cache
28+
forks: 100
29+
connection:
30+
pipelining: true
31+
playbooks:
32+
converge: ../_shared/converge.yml
33+
34+
# TODO: Add this back in when we have a testinfra verifier
35+
# verifier:
36+
# name: testinfra
37+
# directory: ../_shared/tests

molecule/_shared/converge.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
3+
- name: Converge
4+
hosts: all
5+
gather_facts: true
6+
tasks:
7+
- name: Include role
8+
ansible.builtin.include_role:
9+
name: "hanxhx.debian_bootstrap"
10+
vars:
11+
# Force SysVinit, since systemd won't work in a Docker container
12+
ansible_service_mgr: "sysvinit"

molecule/debian-10/molecule.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
3+
platforms:
4+
- name: debian-10
5+
image: dokken/debian-10
6+
command: /lib/systemd/systemd
7+
dockerfile: ../_shared/Dockerfile.j2
8+
capabilities:
9+
- SYS_ADMIN
10+
cgroupns_mode: host
11+
volumes:
12+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
13+
privileged: true

molecule/debian-11/molecule.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
3+
platforms:
4+
- name: debian-11
5+
image: dokken/debian-11
6+
command: /lib/systemd/systemd
7+
dockerfile: ../_shared/Dockerfile.j2
8+
capabilities:
9+
- SYS_ADMIN
10+
cgroupns_mode: host
11+
volumes:
12+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
13+
privileged: true

0 commit comments

Comments
 (0)