question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PY_COLORS fails with vagrant

See original GitHub issue

Issue 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:closed
  • Created 4 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
decentral1secommented, Apr 23, 2019

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.

0reactions
emcniececommented, Aug 10, 2020

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 in logger.py. When the init call is elsewhere (as of v2.22 it’s in shell.py) the charcode stripping doesn’t take effect.

Is this an init race condition? Looks like it with some quick logging:

# shell.py
click_completion.init()
print('shell init')
colorama.init(autoreset=True, strip=not should_do_markup())
print('shell init - colorama done')
...
# logger.py
from ansible.module_utils.parsing.convert_bool import boolean as to_bool
print('logger init')
def should_do_markup():
  ...
$ PY_COLORS=0 molecule test -s myscenario
logger init
shell init
shell init - colorama done

Logger inits before Shell runs colorama.init(), so by the time colorama.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 any from molecule.logger imports, but this fails with the current architecture because colorama.init() relies on from molecule.logger import should_do_markup.

Proposal: move should_do_markup to util.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 imports molecule.logger and as such the logger will still instantiate with pre-init colorama. 😖

Read more comments on GitHub >

github_iconTop Results From Across the Web

No color coding on windows #1581 - hashicorp/vagrant - GitHub
Hello I'm using vagrant in a windows 7 cmd line. There's no color coding, the color code being displayed raw.
Read more >
How to output error in custom color in Vagrant provision script?
This is happening because some tools write some of their messages to stderr , which Vagrant then interprets as an error and prints...
Read more >
Vagrant up - installing ansible via pip syntax error
Vagrant assumes that this means the command failed! curl https://bootstrap.pypa.io/get-pip.py | sudo python Stdout from the command: Stderr ...
Read more >
vagrant login - Command-Line Interface - HashiCorp Developer
The "vagrant login" command is used to authenticate Vagrant with HashiCorp's Vagrant Cloud service to use features like private boxes and "vagrant push"....
Read more >
Vagrant by HashiCorp
Vagrant enables users to create and configure lightweight, reproducible, and portable development environments.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found