PY_COLORS fails with vagrant
See original GitHub issueIssue Type
PY_COLORS does not perform as it was supposed to, it requires sudo. Gitlab CI environment.
Molecule and Ansible details
$ python -V
Python 2.7.5
$ molecule --version
molecule, version 2.20.0
$ ansible --version
ansible 2.7.8
Both installed with pip
Log:
$ sudo molecule destroy -s libvirt –> Validating schema /builds/test/molecule/libvirt/molecule.yml. Validation completed successfully. –> Test matrix
└── libvirt ├── cleanup └── destroy
–> Scenario: ‘libvirt’ –> Action: ‘cleanup’ Skipping, cleanup playbook not configured. –> Scenario: ‘libvirt’ –> Action: ‘destroy’
PLAY [Destroy] *****************************************************************
TASK [Destroy molecule instance(s)] ********************************************
ok: [localhost] => (item=None)
ok: [localhost]
TASK [Populate instance config] ************************************************
ok: [localhost]
TASK [Dump instance config] ****************************************************
skipping: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
$ export PY_COLORS=0 $ molecule destroy -s libvirt –> Validating schema /builds/test/molecule/libvirt/molecule.yml. Validation completed successfully. –> Test matrix
└── libvirt ├── cleanup └── destroy
–> Scenario: ‘libvirt’ –> Action: ‘cleanup’ Skipping, cleanup playbook not configured. –> Scenario: ‘libvirt’ –> Action: ‘destroy’
PLAY [Destroy] *****************************************************************
TASK [Destroy molecule instance(s)] ********************************************
ok: [localhost] => (item=None)
ok: [localhost]
TASK [Populate instance config] ************************************************
ok: [localhost]
TASK [Dump instance config] ****************************************************
skipping: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
$ export PY_COLORS=1 $ molecule destroy -s libvirt –> Validating schema /builds/test/molecule/libvirt/molecule.yml. Validation completed successfully. –> Test matrix
└── libvirt ├── cleanup └── destroy
–> Scenario: ‘libvirt’ –> Action: ‘cleanup’ Skipping, cleanup playbook not configured. –> Scenario: ‘libvirt’ –> Action: ‘destroy’
PLAY [Destroy] *****************************************************************
TASK [Destroy molecule instance(s)] ********************************************
failed: [localhost] (item=None) => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result", "changed": false}
fatal: [localhost]: FAILED! => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result", "changed": false}
PLAY RECAP *********************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1
Detailed log
$ export PY_COLORS=1 $ molecule destroy -s libvirt . . failed: [localhost] (item={‘box’: u’centos/7’, ‘provider_options’: {‘memory’: 1024, ‘cpus’: 1, ‘uri’: u"‘qemu:///system’"}, ‘name’: u’centos7’, ‘groups’: [u’centos’]}) => { “changed”: false, “item”: { “box”: “centos/7”, “groups”: [ “centos” ], “name”: “centos7”, “provider_options”: { “cpus”: 1, “memory”: 1024, “uri”: “‘qemu:///system’” } }, “rc”: 0 }
MSG:
MODULE FAILURE
See stdout/stderr for the exact error
MODULE_STDOUT:
--> Validating schema /builds/ansible/roles/molecule/libvirt/molecule.yml.
Validation completed successfully.
{"invocation": {"module_args": {"config_options": {}, "platform_box_url": null, "provider_cpus": 2, "provider_raw_config_args": null, "platform_box": "centos/7", "provider_override_args": null, "state": "destroy", "instance_interfaces": [], "instance_name": "centos7", "platform_box_version": null, "provider_memory": 512, "instance_raw_config_args": null, "provider_options": {"memory": 1024, "uri": "'qemu:///system'", "cpus": 1}, "provider_name": "libvirt", "provision": false, "force_stop": true}}, "changed": false}
PLAY RECAP *********************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1
Desired Behavior
I would like to use PY_COLORS fully without sudo.
Actual Behaviour
Running as root in the container(gitlab CI executor), tested with privileged and without it. Everything worked with molecule 2.19. I updated to 2.20 and added PY_COLORS=1, now molecule create and destroy fails. Adding sudo lets create and destroy pass through but the color disappears.
It could be somehow issued with gitlab Ci, but it keeps me wondering that with PY_COLORS=0 all works flawlessly.
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (6 by maintainers)
FYI, https://github.com/ansible/molecule/pull/2001 was merged which was chasing some bug related to the colorama code which is also related here. Perhaps give a re-run with the latest master and see if that is working.
https://github.com/ansible-community/molecule/pull/2001 seems to have caused a regression - I can only get Colorama to properly apply
strip=True
when the init call is inlogger.py
. When the init call is elsewhere (as of v2.22 it’s inshell.py
) the charcode stripping doesn’t take effect.Is this an init race condition? Looks like it with some quick logging:
Logger inits before Shell runs
colorama.init()
, so by the timecolorama.init()
sets color stripping the Logger class is instantiated with a pre-init colorama config.This can be resolved by moving
colorama.init()
up above anyfrom molecule.logger
imports, but this fails with the current architecture becausecolorama.init()
relies onfrom molecule.logger import should_do_markup
.Proposal: move
should_do_markup
toutil.py
as it is a functional method and has no package-local dependencies. Does this sound sane?edit: no that won’t work either…
util.py
importsmolecule.logger
and as such the logger will still instantiate with pre-init colorama. 😖