Repository: ansible/molecule

Issue:
build fails on functional tests shard 1/3
# Issue Type

- Bug report

# Desired Behavior

CI green

# Actual Behaviour

Build fails on functional tests shard 1/3, for all versions of Ansible and python

example: https://travis-ci.com/ansible/molecule/jobs/174166218

```
test/functional/docker/test_scenarios.py::test_plugins[plugins-docker-default] PASSED [100%]
=================================== FAILURES ===================================
_____________ test_host_group_vars[host_group_vars-docker-default] _____________
scenario_to_test = 'host_group_vars', with_scenario = None
scenario_name = 'default'
    @skip_unsupported_matrix
    @pytest.mark.parametrize(
        'scenario_to_test, driver_name, scenario_name', [
            ('host_group_vars', 'docker', 'default'),
        ],
        indirect=[
            'scenario_to_test',
            'driver_name',
            'scenario_name',
        ])
    def test_host_group_vars(scenario_to_test, with_scenario, scenario_name):
        options = {
            'all': True,
        }
        cmd = sh.molecule.bake('test', **options)
>       out = pytest.helpers.run_command(cmd, log=False)
../../functional/docker/test_scenarios.py:349: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../conftest.py:43: in run_command
    return util.run_command(cmd)
../../../molecule/util.py:105: in run_command
    return cmd()
../../../.tox/ansible27-functional/lib/python3.7/site-packages/sh.py:1427: in __call__
    return RunningCommand(cmd, call_args, stdin, stdout, stderr)
../../../.tox/ansible27-functional/lib/python3.7/site-packages/sh.py:774: in __init__
    self.wait()
../../../.tox/ansible27-functional/lib/python3.7/site-packages/sh.py:792: in wait
    self.handle_command_exit_code(exit_code)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = --> Validating schema /home/travis/build/ansible/molecule/test/scenarios/host_group_vars/molecule/links/molecule....
    
    
code = 1
    def handle_command_exit_code(self, code):
        """ here we determine if we had an exception, or an error code that we
            weren't expecting to see.  if we did, we create and raise an exception
            """
        ca = self.call_args
        exc_class = get_exc_exit_code_would_raise(code, ca["ok_code"],
                ca["piped"])
        if exc_class:
            exc = exc_class(self.ran, self.process.stdout, self.process.stderr,
                    ca["truncate_exc"])
>           raise exc
E           sh.ErrorReturnCode_1: 
E           
E             RAN: /home/travis/build/ansible/molecule/.tox/ansible27-functional/bin/molecule test --all
E           
E             STDOUT:
E           --> Validating schema /home/travis/build/ansible/molecule/test/scenarios/host_group_vars/molecule/links/molecule.yml.
E           Validation completed successfully.
E           --> Validating schema /home/travis/build/ansible/molecule/test/scenarios/host_group_vars/molecule/default/molecule.yml.
E           Validation completed successfully.
E           --> Test matrix
E               
E           ├── links
E           │   ├── lint
E           │   ├── destroy
E           │   ├── dependency
E           │   ├── syntax
E           │   ├── create
E           │   ├── prepare
E           │   ├── converge
E           │   ├── idempotence
E           │   ├── side_effect
E           │   ├── v... (15851 more, please see e.stdout)
E           
E             STDERR:
../../../.tox/ansible27-functional/lib/python3.7/site-packages/sh.py:815: ErrorReturnCode_1
--------------------------- Captured stdout teardown ---------------------------
    CLEANUP: Destroying instances for all scenario(s)
    --> Validating schema /home/travis/build/ansible/molecule/test/scenarios/host_group_vars/molecule/links/molecule.yml.
    Validation completed successfully.
    --> Validating schema /home/travis/build/ansible/molecule/test/scenarios/host_group_vars/molecule/default/molecule.yml.
    Validation completed successfully.
    --> Test matrix
    
    ├── links
    │   └── destroy
    └── default
        └── destroy
        
    --> Inventory /home/travis/build/ansible/molecule/test/scenarios/host_group_vars/molecule/links/../../host_vars linked to /tmp/molecule/host_group_vars/links/host_vars
    --> Inventory /home/travis/build/ansible/molecule/test/scenarios/host_group_vars/molecule/links/../../group_vars linked to /tmp/molecule/host_group_vars/links/group_vars
    --> Scenario: 'links'
    --> Action: 'destroy'
        
        PLAY [Destroy] *****************************************************************
        
        TASK [Destroy molecule instance(s)] ********************************************
        changed: [localhost] => (item=None)
        changed: [localhost]
        
        TASK [Wait for instance(s) deletion to complete] *******************************
        ok: [localhost] => (item=None)
        ok: [localhost]
        
        TASK [Delete docker network(s)] ************************************************
        
        PLAY RECAP *********************************************************************
        localhost                  : ok=2    changed=1    unreachable=0    failed=0
        
        
    --> Scenario: 'default'
    --> Action: 'destroy'
        
        PLAY [Destroy] *****************************************************************
        
        TASK [Destroy molecule instance(s)] ********************************************
        changed: [localhost] => (item=None)
        changed: [localhost]
        
        TASK [Wait for instance(s) deletion to complete] *******************************
        ok: [localhost] => (item=None)
        ok: [localhost]
        
        TASK [Delete docker network(s)] ************************************************
        
        PLAY RECAP *********************************************************************
        localhost                  : ok=2    changed=1    unreachable=0    failed=0
        
        
    
```



Discussion:
@pilou- you promised to take care of it during IRC meeting :)
IRC meeting: https://meetbot.fedoraproject.org/ansible-molecule/2019-01-30/ansible_molecule_working_group.2019-01-30-19.00.html
@pilou- reproducing issue https://paste.debian.net/1063714

Resolving patch:
diff --git a/molecule/util.py b/molecule/util.py
--- a/molecule/util.py
+++ b/molecule/util.py
@@ -102,7 +102,7 @@ def run_command(cmd, debug=False):
         print_environment_vars(cmd._partial_call_args.get('env', {}))
         print_debug('COMMAND', str(cmd))
         print()
-    return cmd()
+    return cmd(_truncate_exc=False)
 
 
 def os_walk(directory, pattern, excludes=[]):


Test patch:
diff --git a/test/scenarios/host_group_vars/molecule/default/playbook.yml b/test/scenarios/host_group_vars/molecule/default/playbook.yml
--- a/test/scenarios/host_group_vars/molecule/default/playbook.yml
+++ b/test/scenarios/host_group_vars/molecule/default/playbook.yml
@@ -10,7 +10,8 @@
       changed_when: false
 
     - name: Group vars group_var for group example from molecule.yml
-      command: echo "{{ host_group_vars_example_group_one_molecule_yml }} {{ host_group_vars_example_group_two_molecule_yml }}"
+      command: |-
+        echo "{{ host_group_vars_example_group_one_molecule_yml }} {{ host_group_vars_example_group_two_molecule_yml }}"
       changed_when: false
 
     - name: Group vars from group_vars existing directory