-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Naturally it's not complete yet, but it's a start. Relates to #17
- Loading branch information
Showing
14 changed files
with
274 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: molecule | ||
on: [push, pull_request] | ||
|
||
env: | ||
ANSIBLE_FORCE_COLOR: '1' | ||
|
||
jobs: | ||
molecule-slackware: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Install dependencies | ||
run: | | ||
pip install --user molecule[docker] molecule-plugins[docker] | ||
- name: Run Molecule | ||
run: molecule test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
- name: Fail if molecule group is missing | ||
hosts: localhost | ||
tasks: | ||
- name: Print some info | ||
ansible.builtin.debug: | ||
msg: "{{ groups }}" | ||
|
||
- name: Assert group existence | ||
ansible.builtin.assert: | ||
that: "'molecule' in groups" | ||
fail_msg: | | ||
molecule group was not found inside inventory groups: {{ groups }} | ||
- name: Converge | ||
hosts: molecule | ||
vars_files: | ||
- vars.yml | ||
gather_facts: true | ||
tasks: | ||
- name: Check uname | ||
ansible.builtin.raw: uname -a | ||
register: result | ||
changed_when: false | ||
|
||
- name: Print some info | ||
ansible.builtin.assert: | ||
that: result.stdout | regex_search("^Linux") | ||
|
||
# TODO: We are not testing everything here, but it's a start | ||
- name: Banners | ||
ansible.builtin.import_tasks: tasks/banners.yml | ||
- name: PAM | ||
ansible.builtin.import_tasks: tasks/pam.yml | ||
- name: Services | ||
ansible.builtin.import_tasks: tasks/services.yml | ||
- name: login_defs | ||
ansible.builtin.import_tasks: tasks/login_defs.yml | ||
- name: Permissions | ||
ansible.builtin.import_tasks: tasks/filesystem.yml | ||
- name: CA certificates | ||
ansible.builtin.import_tasks: tasks/ca-certs.yml | ||
- name: Misc | ||
ansible.builtin.import_tasks: tasks/misc.yml | ||
- name: Cgroup | ||
ansible.builtin.import_tasks: tasks/cgroup.yml | ||
- name: Display manager | ||
ansible.builtin.import_tasks: tasks/display_managers.yml | ||
- name: Kernel | ||
ansible.builtin.import_tasks: tasks/kernel.yml | ||
- name: Logging | ||
ansible.builtin.import_tasks: tasks/logging.yml | ||
|
||
handlers: | ||
- name: Handlers | ||
ansible.builtin.import_tasks: tasks/handlers.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
- name: Create | ||
hosts: localhost | ||
gather_facts: false | ||
vars: | ||
molecule_inventory: | ||
all: | ||
hosts: {} | ||
molecule: {} | ||
tasks: | ||
- name: Create a container | ||
community.docker.docker_container: | ||
name: "{{ item.name }}" | ||
image: "{{ item.image }}" | ||
state: started | ||
command: sleep 1d | ||
log_driver: json-file | ||
register: result | ||
loop: "{{ molecule_yml.platforms }}" | ||
|
||
- name: Print some info | ||
ansible.builtin.debug: | ||
msg: "{{ result.results }}" | ||
|
||
- name: Fail if container is not running | ||
when: > | ||
item.container.State.ExitCode != 0 or | ||
not item.container.State.Running | ||
ansible.builtin.include_tasks: | ||
file: tasks/create-fail.yml | ||
loop: "{{ result.results }}" | ||
loop_control: | ||
label: "{{ item.container.Name }}" | ||
|
||
- name: Add container to molecule_inventory | ||
vars: | ||
inventory_partial_yaml: | | ||
all: | ||
children: | ||
molecule: | ||
hosts: | ||
"{{ item.name }}": | ||
ansible_connection: community.docker.docker | ||
ansible.builtin.set_fact: | ||
molecule_inventory: > | ||
{{ molecule_inventory | combine(inventory_partial_yaml | from_yaml, recursive=true) }} | ||
loop: "{{ molecule_yml.platforms }}" | ||
loop_control: | ||
label: "{{ item.name }}" | ||
|
||
- name: Dump molecule_inventory | ||
ansible.builtin.copy: | ||
content: | | ||
{{ molecule_inventory | to_yaml }} | ||
dest: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml" | ||
mode: "0600" | ||
|
||
- name: Force inventory refresh | ||
ansible.builtin.meta: refresh_inventory | ||
|
||
- name: Fail if molecule group is missing | ||
ansible.builtin.assert: | ||
that: "'molecule' in groups" | ||
fail_msg: | | ||
molecule group was not found inside inventory groups: {{ groups }} | ||
run_once: true # noqa: run-once[task] | ||
|
||
# we want to avoid errors like "Failed to create temporary directory" | ||
- name: Validate that inventory was refreshed | ||
hosts: molecule | ||
gather_facts: false | ||
tasks: | ||
- name: Check uname | ||
ansible.builtin.raw: uname -a | ||
register: result | ||
changed_when: false | ||
|
||
- name: Display uname info | ||
ansible.builtin.debug: | ||
msg: "{{ result.stdout }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
- name: Destroy molecule containers | ||
hosts: molecule | ||
gather_facts: false | ||
tasks: | ||
- name: Stop and remove container | ||
delegate_to: localhost | ||
community.docker.docker_container: | ||
name: "{{ inventory_hostname }}" | ||
state: absent | ||
auto_remove: true | ||
|
||
- name: Remove dynamic molecule inventory | ||
hosts: localhost | ||
gather_facts: false | ||
tasks: | ||
- name: Remove dynamic inventory file | ||
ansible.builtin.file: | ||
path: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml" | ||
state: absent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
dependency: | ||
name: galaxy | ||
options: | ||
requirements-file: requirements.yml | ||
platforms: | ||
- name: molecule-slackware | ||
image: pyllyukko/slackware | ||
provisioner: | ||
name: ansible | ||
# This playbook needs to reside in the project root directory so that the all the files and templates are found properly | ||
playbooks: | ||
converge: ../../converge.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
collections: | ||
- name: community.docker | ||
version: ">=3.10.4" | ||
- name: community.general | ||
- name: ansible.posix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.