Skip to content

Commit

Permalink
Fix multi-platform tests, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
syndr committed Apr 12, 2024
1 parent 44cfb71 commit 30468d0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
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
6 changes: 2 additions & 4 deletions molecule/default/collections.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
collections:
- name: community.general
- name: community.docker
#- name: git+https://github.com/syndr/ansible-collection-molecule.git
# type: git
# version: latest
- name: syndr.molecule
- name: git+https://github.com/syndr/ansible-collection-molecule.git
type: git
version: 1.4.0-dev

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: syndr.molecule.docker_platform
name: syndr.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

2 changes: 1 addition & 1 deletion roles/docker_platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Role Variables

This role should not be used directly in a playbook, and should instead be used via the `molecule.platform` role.

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

Dependencies
------------
Expand Down
2 changes: 1 addition & 1 deletion roles/ec2_platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ In order to connect to AWS, you will need the following environment variables to

The `AWS_SESSION_TOKEN` variable is only required if you are using temporary credentials.

Full role configuration options are available in the `defaults/main.yml` file.
Full role configuration options are available in the [defaults/main.yml](defaults/main.yml) file.

Dependencies
------------
Expand Down
12 changes: 8 additions & 4 deletions roles/platform/tasks/inventory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,22 @@
fail_msg: "Instance configuration for {{ platform_name }} failed! Check the platform configuration."
success_msg: "Instance configuration for {{ platform_name }} is defined"

- name: 🪲 Current instance config
ansible.builtin.debug:
var: __platform_current_instance_config
verbosity: 1

- name: Instance name matching this already exists in configuration
when:
- __platform_current_instance_config is truthy
- platform_name in __platform_current_instance_config.keys()
- platform_name in __platform_current_instance_config | map(attribute='instance') | list
block:
- name: Mark config update as unneeded
ansible.builtin.set_fact:
__platform_instance_config_update_needed: false

- name: Existing configuration does not match desired
when: __platform_new_instance_config != __platform_current_instance_config |
selectattr('instance', 'equalto', platform_name) | list | first)
when: __platform_new_instance_config != (__platform_current_instance_config | selectattr('instance', 'equalto', platform_name) | list | first)
block:
- name: Remove existing {{ platform_name }} configuration (does not match)
ansible.builtin.set_fact:
Expand All @@ -90,7 +94,7 @@
vars:
__platform_instance_config: "{{ __platform_current_instance_config | default([], true) + [__platform_new_instance_config | default('', true)] }}"
ansible.builtin.copy:
content: "{{ __platform_instance_config | to_yaml }}"
content: "{{ __platform_instance_config | to_nice_yaml(indent=2) }}"
dest: "{{ platform_molecule_ephemeral_directory }}/instance_config.yml"
mode: "0600"

Expand Down

0 comments on commit 30468d0

Please sign in to comment.