-
Notifications
You must be signed in to change notification settings - Fork 95
Description
The Vagrant driver generates inventory with the reserved variable name connection
instead of the proper
ansible_connection
variable, causing Ansible to emit warnings about reserved variable names.
Warning Message
[WARNING]: Found variable using reserved name 'connection'.
Origin: /home/user/.cache/molecule/[]project name/default/inventory/ansible_inventory.yml:14:7
12 -o StrictHostKeyChecking=no
13 ansible_user: vagrant
14 connection: ssh
^ column 7
Environment
Observed with the following version:
- molecule-plugins: 23.6.0
- Ansible: 12 (ansible-core 2.19.x)
- Python: 3.12
- Driver: vagrant
Root Cause
In src/molecule_plugins/vagrant/driver.py
at line 146, the ansible_connection_options
method returns a dictionary with the reserved variable name connection
:
return {
"ansible_user": d["user"],
"ansible_host": d["address"],
"ansible_port": d["port"],
"ansible_private_key_file": d["identity_file"],
"connection": "ssh", # ← Should be "ansible_connection"
"ansible_ssh_common_args": " ".join(self.ssh_connection_options)
}
Ansible Changes & Version Information
The warning about reserved variable names was introduced in ansible-core 2.15 via ansible/ansible#84432
According to the Ansible docs on special variables:
- Special variables like ansible_connection are predefined and automatically populated by Ansible to reflect internal state
- Connection variables control how actions are executed on target hosts
- These variables cannot be directly set by users; Ansible will always override them
The correct variable for controlling connection type is ansible_connection
, not connection
. See https://docs.ansible.com/ansible/latest/plugins/connection.html for details.
Proposed Fix
Change line 146 of vagrant/driver.py from:
"connection": "ssh",
to:
"ansible_connection": "ssh",
This aligns with Ansible's https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_vars_facts.html where
connection-related variables use the ansible_* prefix.
Impact
This is a cosmetic issue that generates warnings but does not break functionality, as Ansible internally handles the
conversion appropriately. However, it creates noise in test output and may concern users who see warnings in their CI/CD
pipelines.
Steps to Reproduce
- Create a molecule scenario using the vagrant driver
- Run molecule test with Ansible 12 (ansible-core 2.15+)
- Observe the warning during the converge phase
Additional Context
- The reserved variable name validation has become stricter with each ansible-core release (2.15, 2.16, 2.17, 2.18, 2.19)
- This affects all users of
molecule-plugins
with the vagrant driver on modern Ansible versions