Repository: ansible/ansible-runner

Issue:
then env/extravars are overwritten
Take code from the  docs and add extraverts variable

```
import ansible_runner
extravars = {
    'ansible_connection': 'local',
    'test': 'extra'
}

r = ansible_runner.run(private_data_dir='/tmp/demo', playbook='test.yml', extravars=extravars)
print("{}: {}".format(r.status, r.rc))
# successful: 0
for each_host_event in r.events:
    print(each_host_event['event'])
print("Final status:")
print(r.stats)
```

take the demo directory from the repository, where `env/extravars` is

```
---
ansible_connection: local
test: val
```

run the ansible runner and check the `env/extravars`

```
{"test": "extra", "ansible_connection": "local"}
```


According the docs in the code **https://ansible-runner.readthedocs.io/en/latest/_modules/ansible_runner/interface.html#run**

```
 :param extravars: Extra variables to be passed to Ansible at runtime using ``-e``. Extra vars will also be
                      read from ``env/extravars`` in ``private_data_dir``.
```

This not true, they are not read at all and are overwritten.

Discussion:

Patch:
diff --git a/ansible_runner/runner_config.py b/ansible_runner/runner_config.py
index 6d462d4..aa1dc22 100644
--- a/ansible_runner/runner_config.py
+++ b/ansible_runner/runner_config.py
@@ -25,10 +25,8 @@ import tempfile
 import logging
 
 from uuid import uuid4
-try:
-    from collections.abc import Mapping
-except ImportError:
-    from collections import Mapping
+from collections import Mapping
+#from distutils.spawn import find_executable
 
 from six import iteritems, string_types
 
@@ -199,10 +197,6 @@ class RunnerConfig(object):
             # Still need to pass default environment to pexpect
             self.env = os.environ.copy()
 
-        # extravars dict passed in via the interface API takes precedence over on-disk
-        if not self.extra_vars and self.loader.isfile('env/extravars'):
-            self.extra_vars = self.loader.abspath('env/extravars')
-
         try:
             self.settings = self.loader.load_file('env/settings', Mapping)
         except ConfigurationError:
@@ -273,6 +267,8 @@ class RunnerConfig(object):
             exec_list.append("--limit")
             exec_list.append(self.limit)
 
+        if self.loader.isfile('env/extravars'):
+            exec_list.extend(['-e', '@{}'.format(self.loader.abspath('env/extravars'))])
         if isinstance(self.extra_vars, dict) and self.extra_vars:
             exec_list.extend(
                 [
@@ -282,8 +278,6 @@ class RunnerConfig(object):
                     )
                 ]
             )
-        elif self.extra_vars:
-            exec_list.extend(['-e', '@%s' % self.extra_vars])
         if self.verbosity:
             v = 'v' * self.verbosity
             exec_list.append('-%s' % v)
diff --git a/ansible_runner/utils.py b/ansible_runner/utils.py
index 2fa2809..58d8464 100644
--- a/ansible_runner/utils.py
+++ b/ansible_runner/utils.py
@@ -14,10 +14,7 @@ import threading
 import pipes
 import uuid
 
-try:
-    from collections.abc import Iterable, Mapping
-except ImportError:
-    from collections import Iterable, Mapping
+from collections import Iterable, Mapping
 from io import StringIO
 from six import string_types
 
@@ -191,14 +188,14 @@ def dump_artifacts(kwargs):
 
     for key in ('envvars', 'extravars', 'passwords', 'settings'):
         obj = kwargs.get(key)
-        if obj:
+        if obj and not os.path.exists(os.path.join(private_data_dir, 'env', key)):
             path = os.path.join(private_data_dir, 'env')
             dump_artifact(json.dumps(obj), path, key)
             kwargs.pop(key)
 
     for key in ('ssh_key', 'cmdline'):
         obj = kwargs.get(key)
-        if obj:
+        if obj and not os.path.exists(os.path.join(private_data_dir, 'env', key)):
             path = os.path.join(private_data_dir, 'env')
             dump_artifact(str(kwargs[key]), path, key)
             kwargs.pop(key)


Test patch:
diff --git a/test/unit/test_runner_config.py b/test/unit/test_runner_config.py
index ec292e9..243bdb3 100644
--- a/test/unit/test_runner_config.py
+++ b/test/unit/test_runner_config.py
@@ -119,14 +119,6 @@ def test_prepare_env_extra_vars_defaults():
     assert rc.extra_vars is None
 
 
-def test_prepare_env_extra_vars():
-    rc = RunnerConfig('/')
-
-    with patch.object(rc.loader, 'isfile', side_effect=lambda x: True):
-        rc.prepare_env()
-        assert rc.extra_vars == '/env/extravars'
-
-
 def test_prepare_env_settings_defaults():
     rc = RunnerConfig('/')
     rc.prepare_env()
@@ -189,9 +181,16 @@ def test_generate_ansible_command():
     cmd = rc.generate_ansible_command()
     assert cmd == ['ansible-playbook', '-i', '/inventory', 'main.yaml']
 
-    rc.extra_vars = '/env/extravars'
+    rc.extra_vars = dict(test="key")
     cmd = rc.generate_ansible_command()
-    assert cmd == ['ansible-playbook', '-i', '/inventory', '-e', '@/env/extravars', 'main.yaml']
+    assert cmd == ['ansible-playbook', '-i', '/inventory', '-e', '\'test="key"\'', 'main.yaml']
+
+    with patch.object(rc.loader, 'isfile', side_effect=lambda x: True):
+        cmd = rc.generate_ansible_command()
+        assert cmd == ['ansible-playbook', '-i', '/inventory', '-e', '@/env/extravars', '-e', '\'test="key"\'', 'main.yaml']
+        rc.extra_vars = None
+        cmd = rc.generate_ansible_command()
+        assert cmd == ['ansible-playbook', '-i', '/inventory', '-e', '@/env/extravars', 'main.yaml']
     rc.extra_vars = None
 
     rc.verbosity = 3