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

Platform manager role and ec2 test platform support #4

Merged
merged 10 commits into from
Apr 12, 2024
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
12 changes: 8 additions & 4 deletions .github/workflows/latest.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
---

name: Update `latest` tag
on:
release:
types: [published]
on:
push:
branches:
- main

jobs:
run:
runs-on: ubuntu-latest

permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -21,3 +24,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


20 changes: 0 additions & 20 deletions .github/workflows/publish.yml

This file was deleted.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ More tips on using Molecule can be found [below](#using-molecule).
The following roles are provided:

* [init](roles/init) - Initialize the Molecule testing framework for a project
* [docker_platform](roles/docker_platform) - Create a docker-based test platform for Molecule
* [platform](roles/platform) - Deploy a Molecule platform for testing
* [docker_platform](roles/docker_platform) - Used by the `platform` role to create a Docker-based test platform
* [ec2_platform](roles/ec2_platform) - Used by the `platform` role to create an EC2-based test platform
* [prepare_controller](roles/prepare_controller) - Prepare a molecule controller to run local code tests

The recommended way to use this collection is to provision Molecule scenarios using the [init role](roles/init). The `init` role provides template configurations that will work in various project types.
Expand Down
4 changes: 2 additions & 2 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace: influxdata
name: molecule

# The version of the collection. Must be compatible with semantic versioning
version: 1.3.1
version: 1.4.0

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down Expand Up @@ -56,7 +56,7 @@ repository: https://github.com/influxdata/ansible-collection-molecule
#homepage: http://example.com

# The URL to the collection issue tracker
#issues: https://github.com/influxdata/ansible-collection-molecule/issues
issues: https://github.com/influxdata/ansible-collection-molecule/issues

# A list of file glob-like patterns used to filter any files or directories that should not be included in the build
# artifact. A pattern is matched from the relative path of the file or directory of the collection directory. This
Expand Down
15 changes: 5 additions & 10 deletions molecule/default/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
tasks:
- name: Create platform
ansible.builtin.include_role:
name: influxdata.molecule.docker_platform
name: influxdata.molecule.platform
vars:
docker_platform_name: "{{ item.name }}"
docker_platform_image: "{{ item.image }}"
docker_platform_systemd: "{{ item.systemd | default(false) }}"
docker_platform_modify_image: "{{ item.modify_image | default(false) }}"
docker_platform_modify_image_buildpath: "{{ item.modify_image_buildpath | default(molecule_ephemeral_directory + '/build') }}"
docker_platform_privileged: "{{ item.privileged | default (false) }}"
docker_platform_hostvars: "{{ item.hostvars | default({}) }}"
docker_platform_state: present
when: item.type == 'docker'
platform_name: "{{ item.name }}"
platform_state: present
platform_type: "{{ item.type }}"
platform_molecule_cfg: "{{ item }}"
loop: "{{ molecule_yml.platforms }}"
loop_control:
label: item.name
Expand Down
15 changes: 10 additions & 5 deletions molecule/default/destroy.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
---

- name: Perform cleanup
hosts: molecule
hosts: localhost
gather_facts: false
tasks:
- name: Remove platform
- name: Remove platform(s)
ansible.builtin.include_role:
name: influxdata.molecule.docker_platform
name: influxdata.molecule.platform
vars:
docker_platform_name: "{{ inventory_hostname }}"
docker_platform_state: absent
platform_name: "{{ item.name }}"
platform_state: absent
platform_type: "{{ item.type }}"
platform_molecule_cfg: "{{ item }}"
loop: "{{ molecule_yml.platforms }}"
loop_control:
label: item.name

98 changes: 45 additions & 53 deletions roles/docker_platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,34 @@ molecule.docker_platform

Create a docker-based test platform for Molecule.

Requirements
------------

1. Molecule should be installed and executable from a location in the users PATH
1. Ansible should be installed, with `ansible-playbook` executable via the users PATH
1. Docker should be installed
1. The current user should be a member of the `docker` group

Role Variables
--------------

```yaml
# Name of this Molecule platform
docker_platform_name: instance

# Whether this platform should be deployed on the current system (present/absent)
docker_platform_state: present
This role is intended to be used via the `molecule.platform` role that is included with this collection, and should not be referenced directly in a playbook.

# Docker image that this platform runs
docker_platform_image: "geerlingguy/docker-rockylinux9-ansible:latest"
Configuration is done via the `platforms` section of the `molecule.yml` file in your Molecule scenario directory.

# Should the provided image be modified at runtime
docker_platform_modify_image: false
Required configuration options are:

# Path to docker build files that should be used to modify the image. Files are treated as templates
# and can contain jinja2 templating language ("{{ my_var }}" etc.)
docker_platform_modify_image_buildpath: "{{ molecule_ephemeral_directory }}/build"
- `name`: Name of the platform (string)
- `type`: `docker`
- `image`: Docker image to use for the platform (string)

# Command to be executed at runtime on the container
# Leave as "" to use container default
docker_platform_command: ""
Optional configuration options are:

# Is this a SystemD enabled container?
docker_platform_systemd: true
- `systemd`: Whether the container should be started with SystemD enabled (boolean)
- `modify_image`: Whether the provided image should be modified at runtime (boolean)
- `modify_image_buildpath`: Path to Docker build files that should be used to modify the image (string)

# A list of Docker volumes that should be attached to the container
docker_platform_volumes: []
Requirements
------------

# Run the container in Privileged mode (greater host access, less security!)
docker_platform_privileged: false
1. Docker should be installed
1. The current user should be a member of the `docker` group

# A list of tmpfs filesystem paths to be passed to the container
docker_platform_tmpfs: []
```
Role Variables
--------------

Configuration that should not require modification:
```yaml
# Filesystem location of the Molecule ephemeral directory. Should not need to be updated by the user of this role!
docker_platform_molecule_ephemeral_directory: "{{ molecule_ephemeral_directory }}"
```
This role should not be used directly in a playbook, and should instead be used via the `molecule.platform` role.

Molecule variables expected:
- `molecule_ephemeral_directory`
Detailed information on configuration variables for this role can be found in [defaults/main.yml](defaults/main.yml).

Dependencies
------------
Expand All @@ -66,36 +41,53 @@ Dependencies
Example Playbook
----------------

This role is intended to be used via the `molecule.platform` role that is included with this collection, and should not be referenced directly in a playbook.

Configuration is done via the `platforms` section of the `molecule.yml` file in your Molecule scenario directory.

```yaml
platforms:
- name: docker-rockylinux9
type: docker
image: geerlingguy/docker-rockylinux9-ansible:latest
systemd: True
modify_image: False
privileged: False
hostvars: {}
```

To utilize this role, use the `platform` role that is included with this collection in your `create.yml` playbook!

```yaml
- name: Create
hosts: localhost
gather_facts: false
tasks:
- name: Create platform
- name: Create platform(s)
ansible.builtin.include_role:
name: influxdata.molecule.docker_platform
name: influxdata.molecule.platform
vars:
docker_platform_name: "{{ item.name }}"
docker_platform_image: "{{ item.image }}"
docker_platform_systemd: true
platform_name: "{{ item.name }}"
platform_state: present
platform_type: "{{ item.type }}"
platform_molecule_cfg: "{{ item }}"
loop: "{{ molecule_yml.platforms }}"
loop_control:
label: item.name

# we want to avoid errors like "Failed to create temporary directory"
- name: Validate molecule inventory
# 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 kernel version
- name: Check uname
ansible.builtin.raw: uname -a
register: result
changed_when: false

- name: Display kernel info
- name: Display uname info
ansible.builtin.debug:
msg: "{{ result.stdout }}"

```


Expand Down
25 changes: 13 additions & 12 deletions roles/docker_platform/tasks/absent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
state: absent
auto_remove: true

- name: Remove dynamic molecule inventory
delegate_to: localhost
block:
- name: Remove dynamic inventory file
ansible.builtin.file:
path: "{{ docker_platform_molecule_ephemeral_directory }}/inventory/molecule_inventory.yml"
state: absent

- name: Remove instance config file
ansible.builtin.file:
path: "{{ docker_platform_molecule_ephemeral_directory }}/instance_config.yml"
state: absent
# TODO: Remove just this host, not the whole inventory
#- name: Remove dynamic molecule inventory
# delegate_to: localhost
# block:
# - name: Remove dynamic inventory file
# ansible.builtin.file:
# path: "{{ docker_platform_molecule_ephemeral_directory }}/inventory/molecule_inventory.yml"
# state: absent
#
# - name: Remove instance config file
# ansible.builtin.file:
# path: "{{ docker_platform_molecule_ephemeral_directory }}/instance_config.yml"
# state: absent


Loading