Skip to content

Commit ee360bc

Browse files
authored
Platform manager role and ec2 test platform support (#4)
Refactor `molecule.docker_platform` role to handle specifically docker testing containers and not molecule inventory files Molecule inventory files are now managed by the new `molecule.platform` role. References to `docker_platform` in molecule `create.yml` or `destroy.yml` files should be updated to use this role in order to work with this version Add `molecule.ec2_platform` role, which allows creation and use of ephemeral ec2 instances for test environments. Update `molecule.init` role to support deployment of both `docker` and `ec2` platforms. Note that only one platform type is supported per scenario! Also note that there are differences between the Molecule configuration for each platform, so this `init` role should be used to deploy the appropriate templates!
1 parent 6f5094d commit ee360bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1641
-326
lines changed

.github/workflows/latest.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
---
22

33
name: Update `latest` tag
4-
on:
5-
release:
6-
types: [published]
4+
on:
5+
push:
6+
branches:
7+
- main
78

89
jobs:
910
run:
1011
runs-on: ubuntu-latest
11-
12+
permissions:
13+
contents: write
14+
packages: write
1215
steps:
1316
- name: Checkout repository
1417
uses: actions/checkout@v4
@@ -21,3 +24,4 @@ jobs:
2124
env:
2225
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2326

27+

.github/workflows/publish.yml

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

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ More tips on using Molecule can be found [below](#using-molecule).
5050
The following roles are provided:
5151

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

5658
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.

galaxy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace: influxdata
88
name: molecule
99

1010
# The version of the collection. Must be compatible with semantic versioning
11-
version: 1.3.1
11+
version: 1.4.0
1212

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

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

6161
# A list of file glob-like patterns used to filter any files or directories that should not be included in the build
6262
# artifact. A pattern is matched from the relative path of the file or directory of the collection directory. This

molecule/default/create.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
tasks:
66
- name: Create platform
77
ansible.builtin.include_role:
8-
name: influxdata.molecule.docker_platform
8+
name: influxdata.molecule.platform
99
vars:
10-
docker_platform_name: "{{ item.name }}"
11-
docker_platform_image: "{{ item.image }}"
12-
docker_platform_systemd: "{{ item.systemd | default(false) }}"
13-
docker_platform_modify_image: "{{ item.modify_image | default(false) }}"
14-
docker_platform_modify_image_buildpath: "{{ item.modify_image_buildpath | default(molecule_ephemeral_directory + '/build') }}"
15-
docker_platform_privileged: "{{ item.privileged | default (false) }}"
16-
docker_platform_hostvars: "{{ item.hostvars | default({}) }}"
17-
docker_platform_state: present
18-
when: item.type == 'docker'
10+
platform_name: "{{ item.name }}"
11+
platform_state: present
12+
platform_type: "{{ item.type }}"
13+
platform_molecule_cfg: "{{ item }}"
1914
loop: "{{ molecule_yml.platforms }}"
2015
loop_control:
2116
label: item.name

molecule/default/destroy.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
---
22

33
- name: Perform cleanup
4-
hosts: molecule
4+
hosts: localhost
55
gather_facts: false
66
tasks:
7-
- name: Remove platform
7+
- name: Remove platform(s)
88
ansible.builtin.include_role:
9-
name: influxdata.molecule.docker_platform
9+
name: influxdata.molecule.platform
1010
vars:
11-
docker_platform_name: "{{ inventory_hostname }}"
12-
docker_platform_state: absent
11+
platform_name: "{{ item.name }}"
12+
platform_state: absent
13+
platform_type: "{{ item.type }}"
14+
platform_molecule_cfg: "{{ item }}"
15+
loop: "{{ molecule_yml.platforms }}"
16+
loop_control:
17+
label: item.name
1318

roles/docker_platform/README.md

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,34 @@ molecule.docker_platform
33

44
Create a docker-based test platform for Molecule.
55

6-
Requirements
7-
------------
8-
9-
1. Molecule should be installed and executable from a location in the users PATH
10-
1. Ansible should be installed, with `ansible-playbook` executable via the users PATH
11-
1. Docker should be installed
12-
1. The current user should be a member of the `docker` group
13-
14-
Role Variables
15-
--------------
16-
17-
```yaml
18-
# Name of this Molecule platform
19-
docker_platform_name: instance
20-
21-
# Whether this platform should be deployed on the current system (present/absent)
22-
docker_platform_state: present
6+
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.
237

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

27-
# Should the provided image be modified at runtime
28-
docker_platform_modify_image: false
10+
Required configuration options are:
2911

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

34-
# Command to be executed at runtime on the container
35-
# Leave as "" to use container default
36-
docker_platform_command: ""
16+
Optional configuration options are:
3717

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

41-
# A list of Docker volumes that should be attached to the container
42-
docker_platform_volumes: []
22+
Requirements
23+
------------
4324

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

47-
# A list of tmpfs filesystem paths to be passed to the container
48-
docker_platform_tmpfs: []
49-
```
28+
Role Variables
29+
--------------
5030

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

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

6035
Dependencies
6136
------------
@@ -66,36 +41,53 @@ Dependencies
6641
Example Playbook
6742
----------------
6843

44+
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.
45+
46+
Configuration is done via the `platforms` section of the `molecule.yml` file in your Molecule scenario directory.
47+
48+
```yaml
49+
platforms:
50+
- name: docker-rockylinux9
51+
type: docker
52+
image: geerlingguy/docker-rockylinux9-ansible:latest
53+
systemd: True
54+
modify_image: False
55+
privileged: False
56+
hostvars: {}
57+
```
58+
59+
To utilize this role, use the `platform` role that is included with this collection in your `create.yml` playbook!
60+
6961
```yaml
7062
- name: Create
7163
hosts: localhost
7264
gather_facts: false
7365
tasks:
74-
- name: Create platform
66+
- name: Create platform(s)
7567
ansible.builtin.include_role:
76-
name: influxdata.molecule.docker_platform
68+
name: influxdata.molecule.platform
7769
vars:
78-
docker_platform_name: "{{ item.name }}"
79-
docker_platform_image: "{{ item.image }}"
80-
docker_platform_systemd: true
70+
platform_name: "{{ item.name }}"
71+
platform_state: present
72+
platform_type: "{{ item.type }}"
73+
platform_molecule_cfg: "{{ item }}"
8174
loop: "{{ molecule_yml.platforms }}"
8275
loop_control:
8376
label: item.name
8477
85-
# we want to avoid errors like "Failed to create temporary directory"
86-
- name: Validate molecule inventory
78+
# We want to avoid errors like "Failed to create temporary directory"
79+
- name: Validate that inventory was refreshed
8780
hosts: molecule
8881
gather_facts: false
8982
tasks:
90-
- name: Check kernel version
83+
- name: Check uname
9184
ansible.builtin.raw: uname -a
9285
register: result
9386
changed_when: false
9487
95-
- name: Display kernel info
88+
- name: Display uname info
9689
ansible.builtin.debug:
9790
msg: "{{ result.stdout }}"
98-
9991
```
10092

10193

roles/docker_platform/tasks/absent.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
state: absent
1212
auto_remove: true
1313

14-
- name: Remove dynamic molecule inventory
15-
delegate_to: localhost
16-
block:
17-
- name: Remove dynamic inventory file
18-
ansible.builtin.file:
19-
path: "{{ docker_platform_molecule_ephemeral_directory }}/inventory/molecule_inventory.yml"
20-
state: absent
21-
22-
- name: Remove instance config file
23-
ansible.builtin.file:
24-
path: "{{ docker_platform_molecule_ephemeral_directory }}/instance_config.yml"
25-
state: absent
14+
# TODO: Remove just this host, not the whole inventory
15+
#- name: Remove dynamic molecule inventory
16+
# delegate_to: localhost
17+
# block:
18+
# - name: Remove dynamic inventory file
19+
# ansible.builtin.file:
20+
# path: "{{ docker_platform_molecule_ephemeral_directory }}/inventory/molecule_inventory.yml"
21+
# state: absent
22+
#
23+
# - name: Remove instance config file
24+
# ansible.builtin.file:
25+
# path: "{{ docker_platform_molecule_ephemeral_directory }}/instance_config.yml"
26+
# state: absent
2627

2728

0 commit comments

Comments
 (0)