Repository: ansible/molecule

Issue:
Molecule crash when defining environment variable for Ansible containes not string
<!--- 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.9.0.dev0
  config file = /home/sshnaidm/.ansible.cfg
  configured module search path = ['/home/sshnaidm/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/sshnaidm/venvs/ansible-dev/src/ansible/lib/ansible
  executable location = /home/sshnaidm/venvs/ansible-dev/bin/ansible
  python version = 3.7.3 (default, May 11 2019, 00:45:16) [GCC 8.3.1 20190223 (Red Hat 8.3.1-2)]

molecule, version 2.22rc2.dev5+g16b7551e.d20190612
```

Molecule installation method (one of):

- pip

Ansible installation method (one of):

- pip

Pre condition:
define provisioner as:
```
provisioner:
  name: ansible
  config_options:
    defaults:
      stdout_callback: debug
  env:
    ANSIBLE_KEEP_REMOTE_FILES: 1
  lint:
    name: ansible-lint
```
when setting ansible env var as int, not string.
This crashes.
The actual problem is in ``sh`` python module, which pass environment as is to ``os.spawnve`` as is: https://github.com/amoffat/sh/blob/master/sh.py#L1402 And ``os.spawnve`` doesn't like if environment are not strings.


# Desired Behavior
Molecule sets environment as string and continues to work.

# Actual Behaviour
Molecule crashes without an error message:
```
DEBUG: ANSIBLE ENVIRONMENT
---
ANSIBLE_CONFIG: /home/sshnaidm/.cache/molecule/startup/default/ansible.cfg
ANSIBLE_FILTER_PLUGINS: /home/sshnaidm/venvs/ansible-dev/src/molecule/molecule/provisioner/ansible/plugins/filters:/home/sshnaidm/.cache/molecule/startup/default/plugins/filters:/home/sshnaidm/sources/local-infr
a/roles/startup/plugins/filters
ANSIBLE_KEEP_REMOTE_FILES: 1
ANSIBLE_LIBRARY: /home/sshnaidm/venvs/ansible-dev/src/molecule/molecule/provisioner/ansible/plugins/libraries:/home/sshnaidm/.cache/molecule/startup/default/library:/home/sshnaidm/sources/local-infra/roles/start
up/library
ANSIBLE_ROLES_PATH: /home/sshnaidm/.cache/molecule/startup/default/roles:/home/sshnaidm/sources/local-infra/roles

DEBUG: MOLECULE ENVIRONMENT
---
MOLECULE_DEBUG: 'True'
MOLECULE_DEPENDENCY_NAME: galaxy
MOLECULE_DRIVER_NAME: podman
MOLECULE_ENV_FILE: /home/sshnaidm/sources/local-infra/roles/startup/.env.yml
MOLECULE_EPHEMERAL_DIRECTORY: /home/sshnaidm/.cache/molecule/startup/default
MOLECULE_FILE: /home/sshnaidm/sources/local-infra/roles/startup/molecule/default/molecule.yml
MOLECULE_INSTANCE_CONFIG: /home/sshnaidm/.cache/molecule/startup/default/instance_config.yml
MOLECULE_INVENTORY_FILE: /home/sshnaidm/.cache/molecule/startup/default/inventory/ansible_inventory.yml
MOLECULE_LINT_NAME: yamllint
MOLECULE_NO_LOG: 'False'
MOLECULE_PROJECT_DIRECTORY: /home/sshnaidm/sources/local-infra/roles/startup
MOLECULE_PROVISIONER_LINT_NAME: ansible-lint
MOLECULE_PROVISIONER_NAME: ansible
MOLECULE_SCENARIO_DIRECTORY: /home/sshnaidm/sources/local-infra/roles/startup/molecule/default
MOLECULE_SCENARIO_NAME: default
MOLECULE_VERIFIER_LINT_NAME: flake8
MOLECULE_VERIFIER_NAME: testinfra
MOLECULE_VERIFIER_TEST_DIRECTORY: /home/sshnaidm/sources/local-infra/roles/startup/molecule/default/tests

DEBUG: SHELL REPLAY
ANSIBLE_CONFIG=/home/sshnaidm/.cache/molecule/startup/default/ansible.cfg ANSIBLE_FILTER_PLUGINS=/home/sshnaidm/venvs/ansible-dev/src/molecule/molecule/provisioner/ansible/plugins/filters:/home/sshnaidm/.cache/m
olecule/startup/default/plugins/filters:/home/sshnaidm/sources/local-infra/roles/startup/plugins/filters ANSIBLE_KEEP_REMOTE_FILES=1 ANSIBLE_LIBRARY=/home/sshnaidm/venvs/ansible-dev/src/molecule/molecule/provisi
oner/ansible/plugins/libraries:/home/sshnaidm/.cache/molecule/startup/default/library:/home/sshnaidm/sources/local-infra/roles/startup/library ANSIBLE_ROLES_PATH=/home/sshnaidm/.cache/molecule/startup/default/ro
les:/home/sshnaidm/sources/local-infra/roles MOLECULE_DEBUG=True MOLECULE_DEPENDENCY_NAME=galaxy MOLECULE_DRIVER_NAME=podman MOLECULE_ENV_FILE=/home/sshnaidm/sources/local-infra/roles/startup/.env.yml MOLECULE_EPHEMERAL_DIRECTORY=/home/sshnaidm/.cache/molecule/startup/default MOLECULE_FILE=/home/sshnaidm/sources/local-infra/roles/startup/molecule/default/molecule.yml MOLECULE_INSTANCE_CONFIG=/home/sshnaidm/.cache/molecule/startup/default/instance_config.yml MOLECULE_INVENTORY_FILE=/home/sshnaidm/.cache/molecule/startup/default/inventory/ansible_inventory.yml MOLECULE_LINT_NAME=yamllint MOLECULE_NO_LOG=False MOLECULE_PROJECT_DIRECTORY=/home/sshnaidm/sources/local-infra/roles/startup MOLECULE_PROVISIONER_LINT_NAME=ansible-lint MOLECULE_PROVISIONER_NAME=ansible MOLECULE_SCENARIO_DIRECTORY=/home/sshnaidm/sources/local-infra/roles/startup/molecule/default MOLECULE_SCENARIO_NAME=default MOLECULE_VERIFIER_LINT_NAME=flake8 MOLECULE_VERIFIER_NAME=testinfra MOLECULE_VERIFIER_TEST_DIRECTORY=/home/sshnaidm/sources/local-infra/roles/startup/molecule/default/tests

DEBUG: COMMAND
/home/sshnaidm/venvs/ansible-dev/bin/ansible-playbook --skip-tags=molecule-notest,notest --diff --inventory=/home/sshnaidm/.cache/molecule/startup/default/inventory /home/sshnaidm/venvs/ansible-dev/src/molecule/molecule/provisioner/ansible/playbooks/podman/destroy.yml -vvv

ERROR: 
```




Discussion:

Resolving patch:
diff --git a/molecule/provisioner/ansible.py b/molecule/provisioner/ansible.py
--- a/molecule/provisioner/ansible.py
+++ b/molecule/provisioner/ansible.py
@@ -492,6 +492,8 @@ def options(self):
     def env(self):
         default_env = self.default_env
         env = self._config.config['provisioner']['env'].copy()
+        # ensure that all keys and values are strings
+        env = {str(k): str(v) for k, v in env.items()}
 
         roles_path = default_env['ANSIBLE_ROLES_PATH']
         library_path = default_env['ANSIBLE_LIBRARY']


Test patch:
diff --git a/test/scenarios/driver/docker/molecule/default/molecule.yml b/test/scenarios/driver/docker/molecule/default/molecule.yml
--- a/test/scenarios/driver/docker/molecule/default/molecule.yml
+++ b/test/scenarios/driver/docker/molecule/default/molecule.yml
@@ -25,6 +25,8 @@ provisioner:
     destroy: ../../../../../resources/playbooks/docker/destroy.yml
   env:
     ANSIBLE_ROLES_PATH: ../../../../../resources/roles/
+    # keep this here to test that we convert integers to strings:
+    SOME_VALUE_AS_INFO: 1
   lint:
     name: ansible-lint
 scenario: