Repository: ansible/molecule

Issue:
If raw_env_vars contains a var whose value is not a string, molecule silently fails to execute Ansible
# Issue Type

- Bug report

# Molecule and Ansible details

```
ansible --version
2.2.0.0

molecule --version

1.14.1.dev37
```

Sha256 of commit is 8eed3f539f0b30b04d98f8ab418a2a5d55cce01f, molecule --version for source checkout seems to be stuck on 1.14

- Molecule installation method: source

# Desired Behaviour

There is no possible key value pair in the ``ansible: {raw_env_vars: {}}`` section that prevents Ansible from getting executed


# Actual Behaviour (Bug report only)

Except from molecule.yml:

```
  raw_env_vars:
    RETRY_FILES_ENABLED: 0
```

```
molecule --debug syntax; echo $?
--> Checking playbook's syntax...
DEBUG: COMMAND
/usr/bin/ansible-playbook tests/test.yml -vvvv --inventory-file=localhost, --syntax-check --limit=all --timeout=30 --diff
255
```

```
$ /usr/bin/ansible-playbook tests/test.yml -vvvv --inventory-file=localhost, --syntax-check --limit=all --timeout=30 --diff; echo $?
Using $ROLE_DIR/ansible.cfg as config file
Set default localhost to localhost
3 plays in tests/test.yml

playbook: tests/test.yml
0
```
The same happens with ``molecule converge``.

This is especially bad since that one is really hard to debug, because there is no error message at all.

I am not even sure if this is the fault of molecule, because [the doc to sh.pys `_env` arg only mentions it must be a dict, not that all values must be string types](https://amoffat.github.io/sh/sections/special_arguments.html?highlight=_env#env).


Discussion:

Resolving patch:
diff --git a/molecule/ansible_playbook.py b/molecule/ansible_playbook.py
--- a/molecule/ansible_playbook.py
+++ b/molecule/ansible_playbook.py
@@ -95,6 +95,8 @@ def parse_arg(self, name, value):
 
         if name == 'raw_env_vars':
             for k, v in value.iteritems():
+                if not isinstance(v, basestring):
+                    v = unicode(v)
                 self.add_env_arg(k, v)
             return
 


Test patch:
diff --git a/test/functional/test_docker_scenarios.py b/test/functional/test_docker_scenarios.py
--- a/test/functional/test_docker_scenarios.py
+++ b/test/functional/test_docker_scenarios.py
@@ -144,6 +144,14 @@ def test_custom_ansible_cfg(scenario_setup):
     assert os.path.exists('ansible.cfg')
 
 
+@pytest.mark.parametrize(
+    'scenario_setup', ['non_string_env'], indirect=['scenario_setup'])
+def test_non_string_env(scenario_setup):
+    sh.molecule('create')
+    sh.molecule('syntax')
+    sh.molecule('destroy')
+
+
 @pytest.mark.parametrize(
     'scenario_setup', ['dockerfile'], indirect=['scenario_setup'])
 def test_dockerfile(scenario_setup):
diff --git a/test/scenarios/non_string_env/molecule.yml b/test/scenarios/non_string_env/molecule.yml
new file mode 100644
--- /dev/null
+++ b/test/scenarios/non_string_env/molecule.yml
@@ -0,0 +1,13 @@
+---
+dependency:
+  name: galaxy
+ansible:
+  raw_env_vars:
+    RETRY_FILES_ENABLED: 0
+driver:
+  name: docker
+docker:
+  containers:
+    - name: non-string-env-scenario
+      image: ubuntu
+      image_version: latest
diff --git a/test/scenarios/non_string_env/playbook.yml b/test/scenarios/non_string_env/playbook.yml
new file mode 100644
--- /dev/null
+++ b/test/scenarios/non_string_env/playbook.yml
@@ -0,0 +1,6 @@
+---
+- hosts: all
+  tasks:
+    - name: Non string environment functional scenario
+      command: /bin/true
+      changed_when: False