How to set no_log: true for molecule internal playbook tasks?
Asked Answered
D

1

6

I am testing version compatibility with molecule and for the combination

python 3.8 x ansible latest x debian

molecule breaks in the instance creation step with

TASK [Wait for instance(s) creation to complete] *******************************
FAILED - RETRYING: Wait for instance(s) creation to complete (300 retries left).
failed: [localhost] (item=None) => {"attempts": 2, "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=6    changed=3    unreachable=0    failed=1    skipped=3    rescued=0    ignored=0

https://travis-ci.com/ckaserer/ansible-role-example/jobs/256557752

In order to debug further, I need to set the no_log: false.

Any ideas on how to set no_log to true for molecule's own internal playbooks?

I tried with MOLECULE_DEBUG, but that did not do the trick.
Searching molecule's doc did not give any results either. running molecule with

molecule --debug test

also does not set the molecule playbook variable for no_log to false

Decorous answered 18/11, 2019 at 15:20 Comment(7)
If you downvote, then please take the time and inform me which additional information would be beneficial such that I can update the question.Decorous
Being precise: you don't want to set no_log: true but no_log: false. In your current context, this is normally done by using the --debug option to molecule (see example for ansible provisionner and docker driver create.yml playbook). I use this every day almost without problems. I suggest you retry and investigate why it does not work as expected on your installation.Afterpiece
Yes, --debug works for your own playbooks, but it seems it does not work for the playbooks defined in molecule. Here is a build with molecule --debug test that still does not show me the details that I need. travis-ci.com/ckaserer/ansible-role-example/jobs/257811789Decorous
I just prooved you above it is supposed to work with the included playbooks and told you I was using this almost everyday while developping with molecule.Afterpiece
Please take a look at the referenced build. As you can see the debug option in molecule sets various environment variables, but it does not set MOLECULE_NO_LOG. at least not in molecule, version 2.22Decorous
I believe you use molecule almost every day, but there is a difference between debug and no_log. no_log should only be used to mask sensitive data and is not affected by the debug flag in molecule.Decorous
in your molecule.yml file, under provisioner: add log: true will give you more output.Lester
D
11

You can set the environment variable

MOLECULE_NO_LOG="false"

and then run your normal molecule command .e.g.

molecule test

That wasn't easy to find, I had to take a look at the source code of molecule and found that

molecule/test/resources/playbooks/docker/create.yml

which is the playbook used to create docker images that are defined by Dockerfile.j2 uses the variable molecule_no_log to set the no_log value in the playbook.

Additionally, in

molecule/test/unit/provisioner/test_ansible.py

the variable molecule_no_log is based on the environment variable MOLECULE_NO_LOG

So, in the end, I just needed to set the appropriate environment variable to false.

Molecule source code

Decorous answered 18/11, 2019 at 16:6 Comment(2)
Setting this environment variable is done in the provisioner section like e.g. ``` provisioner: env: MOLECULE_NO_LOG="false" ```Holub
Nice, I didn't know you could do that. That works too!Decorous

© 2022 - 2024 — McMap. All rights reserved.