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

Allow use of file key inside include_tasks #1020

Merged
merged 1 commit into from
Aug 29, 2020
Merged

Conversation

phihos
Copy link
Contributor

@phihos phihos commented Aug 29, 2020

This PR fixes an already closed but not really fixed issue.
As outlined in #507 (comment) the following example causes an error:

- include_tasks:
    file: included_tasks.yml
    apply:
      tags: sometag

Error output (taken from the comment):

Traceback (most recent call last):
  File "/usr/local/bin/ansible-lint", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/dist-packages/ansiblelint/__main__.py", line 115, in main
    matches.extend(runner.run())
  File "/usr/local/lib/python3.7/dist-packages/ansiblelint/runner.py", line 74, in run
    for child in ansiblelint.utils.find_children(arg, self.playbook_dir):
  File "/usr/local/lib/python3.7/dist-packages/ansiblelint/utils.py", line 163, in find_children
    basedir, item, playbook[1], playbook_dir):
  File "/usr/local/lib/python3.7/dist-packages/ansiblelint/utils.py", line 141, in func_wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/ansiblelint/utils.py", line 215, in play_children
    return delegate_map[k](basedir, k, v, parent_type)
  File "/usr/local/lib/python3.7/dist-packages/ansiblelint/utils.py", line 225, in _include_children
    result = path_dwim(os.path.join(os.path.dirname(basedir)), v)
  File "/usr/local/lib/python3.7/dist-packages/ansiblelint/utils.py", line 73, in path_dwim
    return dl.path_dwim(given)
  File "/usr/local/lib/python3.7/dist-packages/ansible/parsing/dataloader.py", line 186, in path_dwim
    given = unquote(given)
  File "/usr/local/lib/python3.7/dist-packages/ansible/parsing/quoting.py", line 29, in unquote
    if is_quoted(data):
  File "/usr/local/lib/python3.7/dist-packages/ansible/parsing/quoting.py", line 24, in is_quoted
    return len(data) > 1 and data[0] == data[-1] and data[0] in ('"', "'") and data[-2] != '\\'
KeyError: 0

The actual issue here is not the apply statement. It just causes ansible-lint to crash while without it ansible-lint silently behaves strangely.
The root cause is that ansible-lint always expects a single string value for include_tasks.
As seen in the example that is not always the case.

I fixed that by checking for a dict value and extracting its file value for further processing.
Also I expanded an existing test case to cover this kind of include_tasks.

Fixes: #507

Copy link
Member

@ssbarnea ssbarnea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to fix the issue and includes a test. Thanks!

I am looking forward to see more fixed from you.

@ssbarnea ssbarnea added the bug label Aug 29, 2020
@ssbarnea ssbarnea changed the title Fixes #507 Allow use of file key inside include_tasks Aug 29, 2020
@ssbarnea ssbarnea merged commit de48ef9 into ansible:master Aug 29, 2020
@phihos
Copy link
Contributor Author

phihos commented Aug 29, 2020

There is already another one coming 😄

@zoredache
Copy link
Contributor

@phihos thanks for getting this fixed.

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

Successfully merging this pull request may close these issues.

ansible-lint errors when using 2.7+ include_tasks apply argument
3 participants