ansible-playbook-grapher icon indicating copy to clipboard operation
ansible-playbook-grapher copied to clipboard

ansible-playbook-grapher fails with different errors in different versions after upgrading from 1.1.2 to 1.2.0

Open ccamacho opened this issue 2 years ago • 1 comments

Describe the bug

In this new version ansible-playbook-grapher fails with:

Failure with latest: 1.2.0

ansible-playbook-grapher -t task_gather_facts --skip-tags omit_from_grapher -e kubeinit_cluster_distro=okd -e kubeinit_cluster_distro_role=kubeinit_openshift kubeinit/playbook.yml --include-role-tasks -o docs/src/static/playbook_task_gather_facts --save-dot-file

Parsing playbook kubeinit/playbook.yml
Warning: : No inventory was parsed, only implicit localhost is available
Warning: : Looping on tasks or roles are not supported for the moment. Only the
task having the loop argument will be added to the graph.
Warning: : Could not match supplied host pattern, ignoring:
kubeinit_hypervisors
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/ansible/template/__init__.py", line 1160, in do_template
    res = j2_concat(rf)
  File "<template>", line 12, in root
  File "/usr/lib/python3/dist-packages/jinja2/runtime.py", line 639, in _fail_with_undefined_error
    raise self._undefined_exception(hint)
jinja2.exceptions.UndefinedError: 'hostvars' is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-playbook-grapher", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/cli.py", line 269, in main
    cli.run()
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/cli.py", line 61, in run
    grapher.parse(
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/graphbuilder.py", line 86, in parse
    playbook_node = parser.parse()
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/parser.py", line 261, in parse
    self._include_tasks_in_blocks(
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/parser.py", line 379, in _include_tasks_in_blocks
    block_list, _ = task_or_block.get_block_list(
  File "/usr/local/lib/python3.8/dist-packages/ansible/playbook/role_include.py", line 80, in get_block_list
    ri = RoleInclude.load(self._role_name, play=myplay, variable_manager=variable_manager, loader=loader, collection_list=self.collections)
  File "/usr/local/lib/python3.8/dist-packages/ansible/playbook/role/include.py", line 60, in load
    return ri.load_data(data, variable_manager=variable_manager, loader=loader)
  File "/usr/local/lib/python3.8/dist-packages/ansible/playbook/base.py", line 269, in load_data
    ds = self.preprocess_data(ds)
  File "/usr/local/lib/python3.8/dist-packages/ansible/playbook/role/definition.py", line 95, in preprocess_data
    (role_name, role_path) = self._load_role_path(role_name)
  File "/usr/local/lib/python3.8/dist-packages/ansible/playbook/role/definition.py", line 153, in _load_role_path
    role_name = templar.template(role_name)
  File "/usr/local/lib/python3.8/dist-packages/ansible/template/__init__.py", line 886, in template
    result = self.do_template(
  File "/usr/local/lib/python3.8/dist-packages/ansible/template/__init__.py", line 1199, in do_template
    raise AnsibleUndefinedVariable(e)
ansible.errors.AnsibleUndefinedVariable: 'hostvars' is undefined
Failure with: 1.1.3

ansible-playbook-grapher -t task_gather_facts --skip-tags omit_from_grapher -e kubeinit_cluster_distro=okd -e kubeinit_cluster_distro_role=kubeinit_openshift kubeinit/playbook.yml --include-role-tasks -o docs/src/static/playbook_task_gather_facts --save-dot-file

Warning: : No inventory was parsed, only implicit localhost is available
Parsing Play: Perform initial setup on ansible-controller host (localhost) (1) ***
Warning: : Looping on tasks or roles are not supported for the moment. Only the
task having the loop argument will be added to the graph.
Done parsing Play: Perform initial setup on ansible-controller host (localhost) (1) ***
Warning: : Could not match supplied host pattern, ignoring:
Parsing Play: Gather facts from the cluster hypervisor hosts (0) ***************
kubeinit_hypervisors
Done parsing Play: Gather facts from the cluster hypervisor hosts (0) **********
Parsing Play: Determine facts needed to prepare all hypervisor hosts (1) *******
Done parsing Play: Determine facts needed to prepare all hypervisor hosts (1) ***
Parsing Play: Prepare the infrastructure to deploy service and cluster nodes (0) ***
Done parsing Play: Prepare the infrastructure to deploy service and cluster nodes (0) ***
Parsing Play: Run the deployment on the target infrastructure (OpenStack/libvirt hypervisors) (1) ***
Done parsing Play: Run the deployment on the target infrastructure (OpenStack/libvirt hypervisors) (1) ***

Traceback (most recent call last):
  File "/usr/local/bin/ansible-playbook-grapher", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/cli.py", line 249, in main
    cli.run()
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/cli.py", line 71, in run
    svg_path = renderer.render(
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/renderer.py", line 114, in render
    self._convert_to_graphviz()
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/renderer.py", line 391, in _convert_to_graphviz
    self.render_node(
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/renderer.py", line 153, in render_node
    self.render_block(
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/renderer.py", line 244, in render_block
    self.render_node(
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/renderer.py", line 161, in render_node
    self.render_role(
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/renderer.py", line 295, in render_role
    role_color = ":".join([c[0] for c in colors])
  File "/usr/local/lib/python3.8/dist-packages/ansibleplaybookgrapher/renderer.py", line 295, in <listcomp>
    role_color = ":".join([c[0] for c in colors])
TypeError: 'NoneType' object is not subscriptable

Adding a pin works as expected: https://github.com/Kubeinit/kubeinit/pull/702

Do you know what changed that is potentially broken?

Thanks again! Carlos.

ccamacho avatar Sep 16 '22 10:09 ccamacho

The None type error was fixed in 1.2.0.

I will check this undefined variable error.

haidaraM avatar Sep 16 '22 16:09 haidaraM

Hi @ccamacho I'm not able to reproduce your issue locally. Here is what I got with your main branch: Capture d’écran 2022-10-09 à 12 33 16

$ ansible-playbook-grapher --version
ansible-playbook-grapher 1.2.0 (with ansible 2.12.2)

Are you still having the issue with 1.2.0?

haidaraM avatar Oct 09 '22 10:10 haidaraM

Closing this issue. Feel free to re-open it if needed

haidaraM avatar Dec 19 '22 23:12 haidaraM