-
Notifications
You must be signed in to change notification settings - Fork 669
Introduce centralized ansible
configuration section and simplify init command
#4509
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
Merged
Conversation
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
ansible
configuration section and simplify init command
shatakshiiii
approved these changes
Aug 12, 2025
9aafdab
to
1877493
Compare
shatakshiiii
approved these changes
Aug 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! 🎉
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.yml
that 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 scenario
command (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)AnsibleModel
schema definition with nestedcfg
,executor
,env
,playbooks
platforms
optional ifansible:
present, mandatory otherwiseProvisionerModel
to includeansible_args
for validationexecutor
schemasrc/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_CONFIG
with newansible
section defaultsansible.cfg
,ansible.env
,ansible.executor
,ansible.playbooks
src/molecule/types.py
(+73/-14 lines)AnsibleData
TypedDict with nested configuration structuresDefaultConfigData
to includeansible
sectionRuntime Integration Files
src/molecule/provisioner/ansible.py
(+46/-38 lines)ansible_args
,config_options
,env
properties to useansible
sectioninventory
property to handle empty platforms gracefully_verify_inventory
with context-aware validationsrc/molecule/provisioner/ansible_playbooks.py
(+11/-4 lines)_get_playbook
and_get_bundled_driver_playbook
to accessansible.playbooks
src/molecule/model/schema_v3.py
(+17/-14 lines)validate
function to handle optionaldriver
propertiesCommand Interface Files
src/molecule/command/init/scenario.py
(+1/-64 lines)--dependency-name
,--driver-name
,--provisioner-name
scenario_name
CommandArgs
TypedDict 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)ansible
section formattests/unit/provisioner/test_ansible_playbook.py
(+33/-3 lines)ansible.executor
pathtests/unit/test_config.py
(+47/-1 lines)ansible
section 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.