Reverted: Add MOLECULE_SHARED_INVENTORY_DIR environment variable and playbook variable#4500
Merged
cidrblock merged 3 commits intoansible:mainfrom Aug 5, 2025
Merged
Conversation
…book variable Adds support for accessing shared inventory directory in playbooks when using --shared-inventory option. This enables scenarios to create and consume shared inventory files across multiple test runs. - Add MOLECULE_SHARED_INVENTORY_DIR environment variable - Add molecule_shared_inventory_dir playbook variable - Variable is empty string in normal mode and parallel mode - Contains shared inventory path when --shared-inventory is enabled - Update documentation with usage examples - Add comprehensive unit and integration tests
Fix MkDocs build error by properly escaping Jinja2 template variables in code examples using raw blocks to prevent macro rendering errors.
alisonlhart
approved these changes
Aug 5, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add MOLECULE_SHARED_INVENTORY_DIR environment variable and playbook variable
Summary
Introduces
MOLECULE_SHARED_INVENTORY_DIRas both an environment variable and playbook variable to enable access to shared inventory directories when using the--shared-inventoryoption. This enhancement allows scenarios to programmatically create and consume shared inventory files across multiple test runs.Use Case
When testing complex multi-scenario setups, users often need to share inventory data between scenarios. The existing
--shared-inventoryoption provides shared storage but lacks programmatic access from playbooks. This implementation enables:Implementation Details
Core Changes
Environment Variable (
src/molecule/config.py)MOLECULE_SHARED_INVENTORY_DIRto environment variables--shared-inventoryenabled and not in parallel modePlaybook Variable (
src/molecule/provisioner/ansible.py)molecule_shared_inventory_dirto molecule variables available in all playbooks{{ lookup('env', 'MOLECULE_SHARED_INVENTORY_DIR') }}dict[str, str]todict[str, Any]Testing
Unit Tests
tests/unit/test_config.py: Environment variable behavior across all modestests/unit/provisioner/test_ansible.py: Playbook variable inclusion verificationIntegration Tests
tests/fixtures/integration/.../shared_inventory/: Complete test scenario with realistic inventory templatingtests/integration/test_command.py: Dedicated test for shared inventory functionalityDocumentation
Configuration Reference (
docs/configuration.md)Usage Guide (
docs/guides/sharing.md)Behavior
shared_inventoryparallelfalsefalse""(empty)truefalse/path/to/shared/inventorytruetrue""(shared disabled)Example Usage
Compatibility