diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index d3d295c134..5e81508692 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -27,23 +27,23 @@ jobs: - tox_env: docs python-version: 3.9 - tox_env: py38 - PREFIX: PYTEST_REQPASS=455 + PREFIX: PYTEST_REQPASS=456 python-version: 3.8 cover: true - tox_env: py39 - PREFIX: PYTEST_REQPASS=455 + PREFIX: PYTEST_REQPASS=456 python-version: 3.9 cover: true - tox_env: py310 - PREFIX: PYTEST_REQPASS=455 + PREFIX: PYTEST_REQPASS=456 python-version: "3.10" cover: true - tox_env: py38-devel - PREFIX: PYTEST_REQPASS=455 + PREFIX: PYTEST_REQPASS=456 python-version: 3.8 cover: true - tox_env: py310-devel - PREFIX: PYTEST_REQPASS=455 + PREFIX: PYTEST_REQPASS=456 python-version: "3.10" # see https://github.com/ansible-community/molecule/issues/3291 experimental: true diff --git a/docs/configuration.rst b/docs/configuration.rst index 511a3e8344..851ee65b4f 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -10,6 +10,9 @@ Configuration Prerun ------ +Prerun +^^^^^^ + In order to help Ansible find used modules and roles, molecule will perform a prerun set of actions. These involve installing dependencies from ``requirements.yml`` specified at project level, install a standalone role @@ -28,6 +31,21 @@ Keep in mind that you can add this value to the ``.config/molecule/config.yml`` file, in your ``$HOME`` or at the root of your project, in order to avoid adding it to each scenario. +Role name check +^^^^^^^^^^^^^^^ + +By default, ``Molecule`` will check whether the role name follows the name +standard. If not, it will raise an error. + +If computed fully qualified role name does not follow current galaxy +requirements, you can ignore it by adding `role_name_check: 1` inside the +configuration file. + +It is strongly recommended to follow the name standard of `namespace`_ and +`role`_. + +.. _`namespace`: https://galaxy.ansible.com/docs/contributing/namespaces.html#galaxy-namespace-limitations +.. _`role`: https://galaxy.ansible.com/docs/contributing/creating_role.html#role-names Variable Substitution --------------------- diff --git a/src/molecule/command/base.py b/src/molecule/command/base.py index 6a918c817c..9696408bad 100644 --- a/src/molecule/command/base.py +++ b/src/molecule/command/base.py @@ -107,8 +107,11 @@ def execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args=() for scenario in scenarios: if scenario.config.config["prerun"]: - LOG.info("Performing prerun...") - scenario.config.runtime.prepare_environment(install_local=True) + role_name_check = scenario.config.config["role_name_check"] + LOG.info("Performing prerun with role_name_check=%s...", role_name_check) + scenario.config.runtime.prepare_environment( + install_local=True, role_name_check=role_name_check + ) if command_args.get("subcommand") == "reset": LOG.info("Removing %s", scenario.ephemeral_directory) diff --git a/src/molecule/config.py b/src/molecule/config.py index 84251d3a1d..af2f12951d 100644 --- a/src/molecule/config.py +++ b/src/molecule/config.py @@ -360,6 +360,7 @@ def _get_defaults(self) -> MutableMapping: }, "platforms": [], "prerun": True, + "role_name_check": 0, "provisioner": { "name": "ansible", "config_options": {}, diff --git a/src/molecule/test/functional/test_command.py b/src/molecule/test/functional/test_command.py index 1e18f71429..e55e028a0e 100644 --- a/src/molecule/test/functional/test_command.py +++ b/src/molecule/test/functional/test_command.py @@ -337,6 +337,24 @@ def test_command_test_with_platform_name( run_test_with_platform_name(driver_name, platform_name, scenario_name) +@pytest.mark.serial +@pytest.mark.parametrize( + ("scenario_to_test", "driver_name", "scenario_name"), + [ + ( + "driver/delegated_invalid_role_name_with_role_name_check_equals_to_1", + "delegated", + "default", + ), + ], + indirect=["scenario_to_test", "driver_name", "scenario_name"], +) +def test_command_test_with_role_name_check_equals_to_1( + scenario_to_test, with_scenario, scenario_name, driver_name +): + run_test(driver_name, scenario_name) + + @pytest.mark.serial @pytest.mark.extensive @pytest.mark.parametrize( diff --git a/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/meta/main.yml b/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/meta/main.yml new file mode 100644 index 0000000000..23dcc55edd --- /dev/null +++ b/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/meta/main.yml @@ -0,0 +1,8 @@ +--- +dependencies: [] + +galaxy_info: + author: Molecule Developer + description: Role to test ansible_compat installation of role + namespace: molecule + role_name: delegated-test diff --git a/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/molecule/default/converge.yml b/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/molecule/default/converge.yml new file mode 100644 index 0000000000..aa7c05daa1 --- /dev/null +++ b/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/molecule/default/converge.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + gather_facts: false + become: false diff --git a/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/molecule/default/create.yml b/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/molecule/default/create.yml new file mode 100644 index 0000000000..8644efcfdc --- /dev/null +++ b/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/molecule/default/create.yml @@ -0,0 +1,4 @@ +--- +- name: Create + hosts: all + gather_facts: false diff --git a/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/molecule/default/destroy.yml b/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/molecule/default/destroy.yml new file mode 100644 index 0000000000..24304f5b07 --- /dev/null +++ b/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/molecule/default/destroy.yml @@ -0,0 +1,4 @@ +--- +- name: Destroy + hosts: all + gather_facts: false diff --git a/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/molecule/default/molecule.yml b/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/molecule/default/molecule.yml new file mode 100644 index 0000000000..e52066bef3 --- /dev/null +++ b/src/molecule/test/scenarios/driver/delegated_invalid_role_name_with_role_name_check_equals_to_1/molecule/default/molecule.yml @@ -0,0 +1,22 @@ +--- +role_name_check: 1 +driver: + name: delegated +platforms: + - name: instance +provisioner: + name: ansible + inventory: + hosts: + all: + hosts: + instance: + ansible_host: localhost + default_sequence: + - converge + test_sequence: + # - prepare + - converge + # - verify + verify_sequence: + - converge