Introduce centralized ansible configuration section and simplify init command#4509
Merged
cidrblock merged 3 commits intoansible:mainfrom Aug 13, 2025
Merged
Introduce centralized ansible configuration section and simplify init command#4509cidrblock merged 3 commits intoansible:mainfrom
ansible configuration section and simplify init command#4509cidrblock merged 3 commits intoansible:mainfrom
Conversation
ansible configuration section and simplify init command
shatakshiiii
approved these changes
Aug 12, 2025
9aafdab to
1877493
Compare
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.
Summary
This change introduces a new top-level
ansible:section tomolecule.ymlthat centralizes all Ansible-related configuration previously scattered across multiple sections. The enhancement maintains full backward compatibility while providing a cleaner, more intuitive configuration experience.Background
Currently, Ansible configuration is distributed across several sections (
provisioner.ansible_args,provisioner.config_options,executor.backend, etc.), creating confusion and inconsistency. This change consolidates these settings into a single, logical location while supporting modern Ansible tooling patterns.Key Changes
New
ansible:Configuration Section:ansible.cfg: Centralized ansible.cfg configuration optionsansible.env: Environment variables for Ansible executionansible.executor: Backend selection (ansible-playbook/ansible-navigator) with dedicated argument structuresansible.playbooks: Playbook path definitionsEnhanced User Experience:
molecule init scenariocommand (removed unnecessary options)Backward Compatibility:
ansible:sectionTechnical Implementation
Complete Per-File Changes (17 files, +1716/-300 lines)
details
Core Implementation Files
src/molecule/data/molecule.json(+198/-9 lines)AnsibleModelschema definition with nestedcfg,executor,env,playbooksplatformsoptional ifansible:present, mandatory otherwiseProvisionerModelto includeansible_argsfor validationexecutorschemasrc/molecule/config.py(+138/-113 lines)_get_config_with_migration()_migrate_user_config()with support foransible_args,config_options,env,playbooks_get_ansible_key_mapping()helper for debug messagessrc/molecule/constants.py(+123/-1 lines)DEFAULT_CONFIGwith newansiblesection defaultsansible.cfg,ansible.env,ansible.executor,ansible.playbookssrc/molecule/types.py(+73/-14 lines)AnsibleDataTypedDict with nested configuration structuresDefaultConfigDatato includeansiblesectionRuntime Integration Files
src/molecule/provisioner/ansible.py(+46/-38 lines)ansible_args,config_options,envproperties to useansiblesectioninventoryproperty to handle empty platforms gracefully_verify_inventorywith context-aware validationsrc/molecule/provisioner/ansible_playbooks.py(+11/-4 lines)_get_playbookand_get_bundled_driver_playbookto accessansible.playbookssrc/molecule/model/schema_v3.py(+17/-14 lines)validatefunction to handle optionaldriverpropertiesCommand Interface Files
src/molecule/command/init/scenario.py(+1/-64 lines)--dependency-name,--driver-name,--provisioner-namescenario_nameCommandArgsTypedDict for cleaner interfacesrc/molecule/data/init-scenario.yml(-4 lines)src/molecule/data/templates/scenario/molecule.yml.j2(+57/-12 lines)ansible:section exampleTest Files
tests/unit/test_migration_logic.py(+810 lines) - NEW FILEtests/unit/provisioner/test_ansible.py(+141/-17 lines)ansiblesection formattests/unit/provisioner/test_ansible_playbook.py(+33/-3 lines)ansible.executorpathtests/unit/test_config.py(+47/-1 lines)ansiblesection defaults and validationtests/unit/conftest.py(+15/-2 lines)Integration Test Fixtures
tests/fixtures/integration/test_command/molecule/test-scenario*/molecule.yml(+3/-2 lines each)Migration Path
Users can gradually adopt the new
ansible:section while legacy configurations remain functional. Debug logging assists with migration by identifying which legacy keys can be moved to the centralized section.Future Direction
This change encourages the use of Ansible-native inventory management rather than Molecule-managed inventory through legacy keys, aligning with modern Ansible practices and improving integration with existing Ansible toolchains.
Testing
Example Usage
Before (legacy):
After (centralized):
Both configurations work, but the new format provides better organization and modern tooling support.
Documentation
Due to the breadth of changes needed, documentation updates will be in a future PR.