Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix include_role with loop #92

Merged
merged 4 commits into from
Jan 9, 2022
Merged

fix: Fix include_role with loop #92

merged 4 commits into from
Jan 9, 2022

Conversation

haidaraM
Copy link
Owner

@haidaraM haidaraM commented Nov 7, 2021

Should fix #80

@haidaraM haidaraM force-pushed the fix/includeRoleLoop branch 3 times, most recently from b607512 to 6eed68c Compare November 11, 2021 17:31
@haidaraM haidaraM force-pushed the fix/includeRoleLoop branch from 6eed68c to 6ca3cf5 Compare January 6, 2022 22:58
@haidaraM haidaraM marked this pull request as ready for review January 9, 2022 19:23
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 94.595% when pulling 940c585 on fix/includeRoleLoop into c65ffcd on main.

@haidaraM haidaraM merged commit 5615043 into main Jan 9, 2022
@haidaraM haidaraM deleted the fix/includeRoleLoop branch January 9, 2022 19:24
@fiskhest
Copy link

Hi @haidaraM

My impression is that the changes would display a warning, but still continue running what it possibly can parse?

I'm still seeing crashes after trying this code:

❯ ~/.pyenv/versions/3.9.1/envs/apg/bin/ansible-playbook-grapher  entry-plan.yml --include-role-tasks -i inventory/tf_inventory.py
[WARNING]: ansible.utils.display.initialize_locale has not been called, this may result in incorrectly calculated text widths that can cause Display to print incorrect line lengths

Parsing Play: generate plan order (1) **************************************************************************************************************************************************************
[WARNING]: Including role with loop is not supported for the moment. The include will not be evaluated.
Traceback (most recent call last):
  File "/home/johan/.pyenv/versions/3.9.1/envs/apg/bin/ansible-playbook-grapher", line 33, in <module>
    sys.exit(load_entry_point('ansible-playbook-grapher==1.0.1', 'console_scripts', 'ansible-playbook-grapher')())
  File "/home/johan/.pyenv/versions/apg/lib/python3.9/site-packages/ansible_playbook_grapher-1.0.1-py3.9.egg/ansibleplaybookgrapher/cli.py", line 126, in main
    cli.run()
  File "/home/johan/.pyenv/versions/apg/lib/python3.9/site-packages/ansible_playbook_grapher-1.0.1-py3.9.egg/ansibleplaybookgrapher/cli.py", line 43, in run
    playbook_node = parser.parse()
  File "/home/johan/.pyenv/versions/apg/lib/python3.9/site-packages/ansible_playbook_grapher-1.0.1-py3.9.egg/ansibleplaybookgrapher/parser.py", line 179, in parse
    self._include_tasks_in_blocks(current_play=play, parent_nodes=[role_node], block=block,
  File "/home/johan/.pyenv/versions/apg/lib/python3.9/site-packages/ansible_playbook_grapher-1.0.1-py3.9.egg/ansibleplaybookgrapher/parser.py", line 289, in _include_tasks_in_blocks
    self._include_tasks_in_blocks(current_play=current_play, parent_nodes=parent_nodes, block=b,
  File "/home/johan/.pyenv/versions/apg/lib/python3.9/site-packages/ansible_playbook_grapher-1.0.1-py3.9.egg/ansibleplaybookgrapher/parser.py", line 317, in _include_tasks_in_blocks
    parent_node=parent_nodes[-1])
IndexError: list index out of range

I can create a new issue if you'd prefer tracking this separately, just lmk.

@haidaraM
Copy link
Owner Author

Can you provide me a minimal version of your playbook that is failing or run with -vvv and send me the logs?

No need to create a new issue. I will reopen the old one :-)

@haidaraM
Copy link
Owner Author

It displays a warning and moves on to the next task but in your case, I have missed something.

@fiskhest
Copy link

To create a minimal reproducible version of my playbook I reverse engineered to understand what task is failing,

try:
    self._add_task(task=task_or_block, task_vars=play_vars, node_type=node_type,
                   parent_node=parent_nodes[-1])
except IndexError:
    breakpoint()

-> for task_or_block in block.block:
(Pdb) task_or_block
TASK: meta/plan : Include the dynamically generated resource plan
(Pdb)
- name: Include the dynamically generated resource plan
  ansible.builtin.include_vars:
    dir: "{{ tenant_dir }}/pipeline/virtual_machines/"
    name: resources
    hash_behaviour: merge

I tried to replicate the include-pasta I've created a simple role that tries to trigger the same issue but that runs as intended. The source is too complex and containing secrets that I do not wish to share. Will continue trying to replicate it minimally but I got no further ideas so leaving this here for now.

@haidaraM
Copy link
Owner Author

Ok. Can you try the version on this PR #99 ?

@fiskhest
Copy link

Certainly, one moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

include_role within a loop on role name to include generates an error
3 participants