$ ansible --version
ansible 2.1.1.0
config file =
configured module search path = Default w/o overrides
$ molecule --version
1.8.4
$ testinfra --version
This is pytest version 3.0.4, imported from /usr/local/lib/python2.7/dist-packages/pytest.pyc
setuptools registered plugins:
pytest-spec-1.0.1 at /usr/local/lib/python2.7/dist-packages/pytest_spec/plugin.py
pytest-xdist-1.15.0 at /usr/local/lib/python2.7/dist-packages/xdist/boxed.py
pytest-xdist-1.15.0 at /usr/local/lib/python2.7/dist-packages/xdist/looponfail.py
pytest-xdist-1.15.0 at /usr/local/lib/python2.7/dist-packages/xdist/plugin.py
testinfra-1.4.2 at /usr/local/lib/python2.7/dist-packages/testinfra/plugin.py
Running commands like molecule converge or molecule verify should emit output with ansi-color escape sequences when ANSIBLE_FORCE_COLOR=true (for ansible) and color: 'yes' (for testinfra) is set.
Whenever molecule converge or molecule verify is being run on our CI server (Ubuntu Server 16.04) we don't get any colors. Invoking testinfra --color=yes standalone (without going through molecule) properly emits the ansi color escape sequences.
It works when connected to the CI server via terminal, but does not for the CI builds.
Any ideas what it needs to trigger colored output? Any env var or similar that needs to be present to make molecule think it runs inside a terminal?
I have tried faking TERM=xterm molecule verify but that did not help. Any ideas what it could be?
Here is the molecule --debug output:
+ molecule converge --debug
DEBUG: RUNNING CONFIG
!!python/unicode 'ansible':
!!python/unicode 'ask_sudo_pass': false
!!python/unicode 'ask_vault_pass': false
config_file: !!python/unicode '.molecule/ansible.cfg'
!!python/unicode 'diff': true
!!python/unicode 'host_key_checking': false
inventory_file: !!python/unicode '.molecule/ansible_inventory'
!!python/unicode 'limit': !!python/unicode 'all'
!!python/unicode 'playbook': site.yml
raw_env_vars:
ANSIBLE_FORCE_COLOR: 'true'
ANSIBLE_ROLES_PATH: ./roles
!!python/unicode 'raw_ssh_args':
- -o ControlMaster=no
!!python/unicode 'sudo': true
!!python/unicode 'sudo_user': false
!!python/unicode 'tags': false
!!python/unicode 'timeout': 30
!!python/unicode 'vault_password_file': false
!!python/unicode 'verbose': vv
!!python/unicode 'molecule':
!!python/unicode 'ansible_config_template': !!python/unicode 'ansible.cfg.j2'
!!python/unicode 'config_file': !!python/unicode '.molecule/ansible.cfg'
!!python/unicode 'default_provider': !!python/unicode 'virtualbox'
!!python/unicode 'ignore_paths':
- !!python/unicode '.git'
- !!python/unicode '.vagrant'
- !!python/unicode '.molecule'
!!python/unicode 'init':
!!python/unicode 'platform':
!!python/unicode 'box': !!python/unicode 'trusty64'
!!python/unicode 'box_url': !!python/unicode 'https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/14.04/providers/virtualbox.box'
!!python/unicode 'box_version': !!python/unicode '0.1.0'
!!python/unicode 'name': !!python/unicode 'trusty64'
!!python/unicode 'templates':
!!python/unicode 'molecule': !!python/unicode 'molecule.yml.j2'
!!python/unicode 'molecule_docker': !!python/unicode 'molecule_docker.yml.j2'
!!python/unicode 'molecule_openstack': !!python/unicode 'molecule_openstack.yml.j2'
!!python/unicode 'playbook': !!python/unicode 'playbook.yml.j2'
!!python/unicode 'test_default': !!python/unicode 'test_default.py.j2'
!!python/unicode 'inventory_file': !!python/unicode '.molecule/ansible_inventory'
!!python/unicode 'molecule_dir': !!python/unicode '.molecule'
!!python/unicode 'molecule_file': !!python/unicode 'molecule.yml'
!!python/unicode 'rakefile_file': !!python/unicode '.molecule/rakefile'
!!python/unicode 'rakefile_template': !!python/unicode 'rakefile.j2'
!!python/unicode 'raw_ssh_args':
- !!python/unicode '-o StrictHostKeyChecking=no'
- !!python/unicode '-o UserKnownHostsFile=/dev/null'
!!python/unicode 'serverspec_dir': disabled
!!python/unicode 'state_file': !!python/unicode '.molecule/state.yml'
!!python/unicode 'test':
!!python/unicode 'sequence':
- !!python/unicode 'destroy'
- !!python/unicode 'syntax'
- !!python/unicode 'create'
- !!python/unicode 'converge'
- !!python/unicode 'idempotence'
- !!python/unicode 'verify'
!!python/unicode 'testinfra_dir': spec
!!python/unicode 'vagrantfile_file': !!python/unicode '.molecule/vagrantfile'
!!python/unicode 'vagrantfile_template': !!python/unicode 'vagrantfile.j2'
!!python/unicode 'testinfra':
color: 'yes'
spec: true
vagrant:
instances:
- name: jenkins-master
raw_config_args:
- 'vm.network ''forwarded_port'', guest: 8080, host: 8080'
- 'vm.network ''forwarded_port'', guest: 443, host: 9443'
- 'vm.network ''forwarded_port'', guest: 80, host: 9080'
vm_name: jenkins-master
platforms:
- box: pvt/ubuntu1604_2.0.19.2
box_url: http://acme.org/vm/boxes/virtualbox/acme-ubuntu1604-2.0.19.2.box
name: ubuntu1604
providers:
- name: virtualbox
options:
cpus: 2
memory: 512
type: virtualbox
- name: vmware_workstation
options:
cpus: 2
memory: 512
type: vmware_workstation
raw_config_args:
- ssh.insert_key = false
DEBUG: OTHER ENVIRONMENT
BRANCH_NAME: feature/pipeline-do-try
BUILD_DISPLAY_NAME: '#6'
BUILD_ID: '6'
BUILD_NUMBER: '6'
BUILD_TAG: jenkins-base-jenkins-master-ci-feature%2Fpipeline-do-try-6
BUILD_URL: http://jenkins.acme.org:8080/job/base-jenkins-master-ci/job/feature%252Fpipeline-do-try/6/
EXECUTOR_NUMBER: '0'
HOME: /var/lib/jenkins
HUDSON_COOKIE: 09a4449a-9a0f-4e15-8bcb-1d2d697e90d5
HUDSON_HOME: /var/lib/jenkins
HUDSON_SERVER_COOKIE: f14756e821a61b55
HUDSON_URL: http://jenkins.acme.org:8080/
JENKINS_HOME: /var/lib/jenkins
JENKINS_SERVER_COOKIE: durable-a1ebb6a1a86ac4c2eba805834346a952
JENKINS_URL: http://jenkins.acme.org:8080/
JOB_BASE_NAME: feature%2Fpipeline-do-try
JOB_NAME: base-jenkins-master-ci/feature%2Fpipeline-do-try
JOB_URL: http://jenkins.acme.org:8080/job/base-jenkins-master-ci/job/feature%252Fpipeline-do-try/
LANG: en_US.UTF-8
LANGUAGE: en_US:en
LOGNAME: jenkins
MAIL: /var/mail/jenkins
NODE_LABELS: devops linux slavelnx3 virtualbox
NODE_NAME: slavelnx3
OLDPWD: /var/lib/jenkins
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
PWD: /var/lib/jenkins/workspace/-ci_feature_pipeline-do-try-QIDPM2HSCTHEA7XK3RJVLQXRZFTCMMY7RFTVOTO2ZYZHTF7XXUYA
PYTHONUNBUFFERED: '1'
SHELL: /bin/bash
SHLVL: '1'
SSH_CLIENT: 192.168.249.53 46922 22
SSH_CONNECTION: 192.168.249.53 46922 192.168.249.54 22
USER: jenkins
VAGRANT_DEFAULT_PROVIDER: virtualbox
WORKSPACE: /var/lib/jenkins/workspace/-ci_feature_pipeline-do-try-QIDPM2HSCTHEA7XK3RJVLQXRZFTCMMY7RFTVOTO2ZYZHTF7XXUYA
XDG_RUNTIME_DIR: /run/user/999
XDG_SESSION_ID: '1657'
_: /usr/bin/java
DEBUG: ANSIBLE ENVIRONMENT
ANSIBLE_CONFIG: !!python/unicode '.molecule/ansible.cfg'
ANSIBLE_FORCE_COLOR: 'true'
ANSIBLE_HOST_KEY_CHECKING: 'false'
ANSIBLE_ROLES_PATH: ./roles
ANSIBLE_SSH_ARGS: -o ControlMaster=no
DEBUG: ANSIBLE PLAYBOOK
/usr/local/bin/ansible-playbook site.yml -vv --inventory-file=.molecule/ansible_inventory --sudo --connection=ssh --limit=all --user=vagrant --timeout=30 --diff
--> Starting Ansible Run ...
Using .molecule/ansible.cfg as config file
PLAYBOOK: site.yml *************************************************************
1 plays in site.yml
PLAY [jenkins-master] **********************************************************
TASK [setup] *******************************************************************
ok: [jenkins-master]
...
Hi @tknerr we are not making any bug fixes to any other branches but master and the current release. Please upgrade to the current version and see if you still have the same problem.
Hi @retr0h, sure, I was not expecting to have a bugfix backported to the quite outdated molecule version we are using here. I was merely looking for an idea what could be the cause for this behaviour and possible ways to work around it.
While I still have to test that behaviour with a more recent version, any suggestions / ideas are very welcome in the meanwhile.
I can't seem to replicate on current version of molecule. We get some color output when making testinfra run with verbose.

You can replicate the issue by running molecule anywhere that at TTY isn't present (every CI platform, Gitlab, Jenkins etc.). This is an issue in the current version of molecule.
This can be replicated very easily: just run molecule from inside tox, something likely to happed on python projects where tox is used to run tests.
Opposed to Ansible, Molecule does not respect the ANSIBLE_FORCE_COLOR=1 variable and always run without colors when there is no tty (tox, ci,...).
Another way to replicate it to enable stdout redirection, another case where coloring is disabled with no way to force it to be enabled.
Because molecule is part of the ansible family I would recommend to respect ANSIBLE_FORCE_COLOR variable when defined.
@retr0h is there any update on this? Is a colorized output in a non tty environment supported or not? I tried multiple things, putting the ansible setting under raw_env_vars:, ansiblecfg_defaults directly as environment variable but nothing works...
Yes, there is an open PR at https://github.com/ansible/molecule/pull/1533 that tries to address this issue by following the PY_COLORS=1 variable.
Most helpful comment
This can be replicated very easily: just run molecule from inside tox, something likely to happed on python projects where tox is used to run tests.
Opposed to Ansible, Molecule does not respect the ANSIBLE_FORCE_COLOR=1 variable and always run without colors when there is no tty (tox, ci,...).
Another way to replicate it to enable stdout redirection, another case where coloring is disabled with no way to force it to be enabled.
Because molecule is part of the ansible family I would recommend to respect ANSIBLE_FORCE_COLOR variable when defined.