Repository: ansible/molecule

Issue:
Extra vars are not passed to the playbook anymore with converge.
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Please also check https://molecule.readthedocs.io/en/latest/faq.html --->
<!--- Please use https://groups.google.com/forum/#!forum/molecule-users for usage questions -->

# Issue Type

- Bug report

# Molecule and Ansible details

```
ansible 2.8.0
  config file = None
  configured module search path = ['/home/olcla/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0]

molecule (downgraded to 2.20 to fix but problem related to master branch)
```

Molecule installation method (one of):

- pip from git master

Ansible installation method (one of):

- pip

# Desired Behavior

When running `molecule converge -s my_scenario -- -e somevar=value` I expect molecule to pass the extra vars when running playbook.yml

# Actual Behaviour

I was trying to fix deprecations related to ansible 2.8 and had to install molecule from git master to overcome problems with testinfra. When running the above command with the latest molecule master, the extra vars are not passed to the playbook anymore. This is working as expected when downgrading to molecule 2.20.1 




Discussion:
I broke this in #1739. Sorry about that. I'll get it fixed, and also get it covered by a test so it doesn't happen again. :)

Resolving patch:
diff --git a/molecule/command/base.py b/molecule/command/base.py
--- a/molecule/command/base.py
+++ b/molecule/command/base.py
@@ -72,7 +72,10 @@ def _setup(self):
         self._config.provisioner.manage_inventory()
 
 
-def execute_cmdline_scenarios(scenario_name, args, command_args):
+def execute_cmdline_scenarios(scenario_name,
+                              args,
+                              command_args,
+                              ansible_args=()):
     """
     Execute scenario sequences based on parsed command-line arguments.
 
@@ -90,7 +93,7 @@ def execute_cmdline_scenarios(scenario_name, args, command_args):
 
     """
     scenarios = molecule.scenarios.Scenarios(
-        get_configs(args, command_args), scenario_name)
+        get_configs(args, command_args, ansible_args), scenario_name)
     scenarios.print_matrix()
     for scenario in scenarios:
         try:
diff --git a/molecule/command/converge.py b/molecule/command/converge.py
--- a/molecule/command/converge.py
+++ b/molecule/command/converge.py
@@ -102,4 +102,5 @@ def converge(ctx, scenario_name, ansible_args):  # pragma: no cover
         'subcommand': subcommand,
     }
 
-    base.execute_cmdline_scenarios(scenario_name, args, command_args)
+    base.execute_cmdline_scenarios(scenario_name, args, command_args,
+                                   ansible_args)


Test patch:
diff --git a/test/unit/command/test_converge.py b/test/unit/command/test_converge.py
--- a/test/unit/command/test_converge.py
+++ b/test/unit/command/test_converge.py
@@ -18,7 +18,10 @@
 #  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 #  DEALINGS IN THE SOFTWARE.
 
+from click.testing import CliRunner
+
 from molecule.command import converge
+from molecule.shell import main
 
 
 # NOTE(retr0h): The use of the `patched_config_validate` fixture, disables
@@ -38,3 +41,19 @@ def test_execute(mocker, patched_logger_info, patched_ansible_converge,
     patched_ansible_converge.assert_called_once_with()
 
     assert config_instance.state.converged
+
+
+def test_ansible_args_passed_to_scenarios_get_configs(mocker):
+    # Scenarios patch is needed to safely invoke CliRunner
+    # in the test environment and block scenario exectution
+    mocker.patch('molecule.scenarios.Scenarios')
+    patched_get_configs = mocker.patch('molecule.command.base.get_configs')
+
+    runner = CliRunner()
+    args = ('converge', '--', '-e', 'testvar=testvalue')
+    ansible_args = args[2:]
+    runner.invoke(main, args, obj={})
+
+    # call index [0][2] is the 3rd positional arguement to get_configs,
+    # which should be the tuple of parsed ansible_args from the CLI
+    assert patched_get_configs.call_args[0][2] == ansible_args