ansible / molecule

Molecule aids in the development and testing of Ansible content: collections, playbooks and roles
https://ansible.readthedocs.io/projects/molecule/
MIT License
3.88k stars 662 forks source link

Can't specify Ansible verbosity as a molecule option #3159

Open hluaces opened 3 years ago

hluaces commented 3 years ago

Apologies if this is working as intended. I've tried to search for it but didn't see anywhere that this was a deprecation change.

Specifying the vvv: true option on the provider section of a molecule.yml has no effect even when molecule is ran with or without the --debug flag.

The documentation, under the section which explains how to override playbook files, shows the following snippet:

provisioner:
  name: ansible
  options:
    vvv: True
  playbooks:
    create: create.yml
    converge: converge.yml
    destroy: destroy.yml

Using vvv: True has no effect. Using vvv: true also has no effect. This used to work on previous molecule versions (3.0.x if I recall correctly).

I'm aware that there are alternatives, such as:

I'm opening this issue just to clarify wether this is an intentional change or not. In case it is I guess that that documentation should be fixed.

Issue Type

Molecule and Ansible details

ansible [core 2.11.1] 
  config file = None
  configured module search path = ['/home/hector/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/hector/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/hector/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/hector/.local/bin/ansible
  python version = 3.8.5 (default, May 27 2021, 13:30:53) [GCC 9.3.0]
  jinja version = 2.11.2
  libyaml = True
molecule 3.3.4 using python 3.8 
    ansible:2.11.1
    delegated:3.3.4 from molecule
    docker:0.3.3 from molecule_docker
    vagrant:0.6.1 from molecule_vagrant

Molecule installation method (one of):

Ansible installation method (one of):

Detail any linters or test runners used:

Desired Behavior

Either the documentation should not provide examples with the vv option and say that option does not work or specifying the options v, vv or vvv, ... in the molecule file should pass the desired verbosity to the ansible-playbook command.

Actual Behaviour

ansible-playbook is ran without verbosity (the -vvv parameter).

There's a minimum complete verifiable example in this repo.

This is the output of a molecule --debug converge with the vvv: true option set (note that no -vvv flag is passed to ansible-playbook):

COMMAND: ansible-playbook --diff --inventory /home/hector/.cache/molecule/molecule_bug_vvv/default/inventory --skip-tags molecule-notest,notest /home/hector/repos/github/molecule/molecule_bug_vvv/molecule/default/converge.yml

PLAY [Converge] ****************************************************************

TASK [Gathering Facts] *********************************************************
ok: [python]

TASK [Include molecule_bug_vvv] ************************************************

TASK [molecule_bug_vvv : This is a command that shows some output] *************
changed: [python]

PLAY RECAP *********************************************************************
python                     : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ssbarnea commented 3 years ago

I do not remember removing such a feature myself and I am inclined to believe that we should just remove it from the docs. Having an yaml option vvv does not make any sense to me, what about 1, 2, 3, or 5 v's? ;)

hluaces commented 3 years ago

Just in case my original issue wasn't clear: the docs mention vvv but v, vv, ... all worked as expected.

IMHO removing it seems fine but it should be acknowledged that it won't work in the docs to prevent people from trying to figure out why it doesn't.

jrgoldfinemiddleton commented 3 years ago

I think this feature is very useful. Not sure why it has been removed, but I don't think it should be. When you use the ANSIBLE_VERBOSITY environment variable, you actually end up getting all molecule phases outputting at that verbosity level rather than just the provisioner phases.

hluaces commented 3 years ago

Have you tried using one of the following options and see if it fits for your use case?

jrgoldfinemiddleton commented 3 years ago

Hi @hluaces, I'm using molecule test instead of molecule converge. The first option you proposed has the same effect as using ANSIBLE_VERBOSITY=3 while the second doesn't work with molecule test.

timblaktu commented 2 years ago

I'm not able to get molecule to pass ANY amount of -v to ansible-playbook using any techniques mentioned:

  1. passing -vvv or --debug to molecule
  2. using
    provisioner:
    name: ansible
    options:
    vvv: True
  3. exporting ANSIBLE_VERBOSITY=3 env var.

Some of these make molecule more verbose, but the call to the converge.yml playbook is still the vanilla:

ansible-playbook --inventory /home/tim/.cache/molecule/ansible/deb10-headless/inventory --skip-tags molecule-notest,notest /home/tim/src/timblaktu-cm/ansible/molecule/deb10-headless/converge.yml

Trying to troubleshoot an ansible issue within molecule and not getting enough info..

it-sova commented 2 years ago

Also faced the same problem, passing env to provisioner seems to work fine:

...
provisioner:
  name: ansible
  env:
    ANSIBLE_VERBOSITY: 3
...
gtirloni commented 2 months ago

I have tried everything is this issue report and nothing works.

Many of the options listed here will result in a jinja2 exception:

Run molecule test -s myscenario
WARNING  Driver docker does not provide a schema.
INFO     myscenario scenario test matrix: dependency, cleanup, destroy, syntax, create, prepare, converge, idempotence, side_effect, verify, cleanup, destroy
INFO     Performing prerun with role_name_check=0...
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.14/x64/bin/molecule", line 8, in <module>
    sys.exit(main())
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/command/test.py", line 110, in test
    base.execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/command/base.py", line 146, in execute_cmdline_scenarios
    execute_scenario(scenario)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/command/base.py", line 1[9]()7, in execute_scenario
    execute_subcommand(scenario.config, action)
  File "/opt/hostedtoolcache/Python/3.[10]().14/x64/lib/python3.10/site-packages/molecule/command/base.py", line 187, in execute_subcommand
    return command(current_config).execute(args)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/command/base.py", line 71, in __init__
    self._setup()
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/command/base.py", line 93, in _setup
    self._config.provisioner.write_config()
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/provisioner/ansible.py", line 771, in write_config
    template = util.render_template(  # type: ignore[no-untyped-call]
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/util.py", line 188, in render_template
    return t.render(kwargs)  # type: ignore[attr-defined]
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/jinja2/environment.py", line [13]()04, in render
    self.environment.handle_exception()
  File "/opt/hostedtoolcache/Python/3.10.[14]()/x64/lib/python3.10/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 3, in top-level template code
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/jinja2/utils.py", line 83, in from_obj
    if hasattr(obj, "jinja_pass_arg"):
jinja2.exceptions.UndefinedError: 'bool object' has no attribute 'items'
Error: Process completed with exit code 1.