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

Allow bypassing role name checking #3549

Merged
merged 1 commit into from
Jun 1, 2022
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
10 changes: 5 additions & 5 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
---------------------
Expand Down
7 changes: 5 additions & 2 deletions src/molecule/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/molecule/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ def _get_defaults(self) -> MutableMapping:
},
"platforms": [],
"prerun": True,
"role_name_check": 0,
"provisioner": {
"name": "ansible",
"config_options": {},
Expand Down
18 changes: 18 additions & 0 deletions src/molecule/test/functional/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Converge
hosts: all
gather_facts: false
become: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Create
hosts: all
gather_facts: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Destroy
hosts: all
gather_facts: false
Original file line number Diff line number Diff line change
@@ -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