ansible / ansible-lint

ansible-lint checks playbooks for practices and behavior that could potentially be improved and can fix some of the most common ones for you
https://ansible.readthedocs.io/projects/lint/
GNU General Public License v3.0
3.49k stars 660 forks source link

Incorrect type guessing for an included playbook #640

Closed bvergnaud closed 4 years ago

bvergnaud commented 4 years ago

Issue Type

Ansible and Ansible Lint details

➜ ansible --version
ansible 2.8.7
  config file = /home/bvergnaud/git/gitlab.infra.online.net/platform/ansible-playbooks/ansible.cfg
  configured module search path = ['/home/bvergnaud/git/gitlab.infra.online.net/platform/ansible-playbooks/library', '/home/bvergnaud/git/gitlab.infra.online.net/platform/ansible-playbooks/library/foreman/plugins/modules']
  ansible python module location = /home/bvergnaud/.local/share/virtualenvs/ansible-playbooks-VBzdj4yE/lib/python3.8/site-packages/ansible
  executable location = /home/bvergnaud/.local/share/virtualenvs/ansible-playbooks-VBzdj4yE/bin/ansible
  python version = 3.8.0 (default, Oct 23 2019, 18:51:26) [GCC 9.2.0]

~/git/gitlab.infra.online.net/platform/ansible-playbooks on  master [$!?] via 🐍 v3.8.0 (ansible-playbooks-VBzdj4yE) 
➜ ansible-lint --version
ansible-lint 4.2.0rc1

Desired Behaviour

When importing a playbook from within another playbook, ansible-lint should properly guess that it is a type playbook.

Actual Behaviour (Bug report only)

When you include a playbook in the pre-tasks sections (we need that secondary playbook to play before the roles) the linter guess its type as 'pre_tasks', and reports the following error multiple times in my case (I didn't manage to find what the number of error is based on): Error trying to append skipped rules: RuntimeError('Unexpected file type: pre_tasks').

Example playbook1.yml :

---
- name: Do something
  hosts: "some_host"
  pre_tasks:
    - name: Do something before the roles
      include: playbook2.yml

  roles:
    - role1

The included playbook2.yml is another playbook right next to the first one, and could contain anything. The error does not cause the return code to change which is lucky in my case as I'm trying to bake it in the pre-commit routine.

webknjaz commented 4 years ago

@bvergnaud did it work in 4.1?

bvergnaud commented 4 years ago

Yes it did. However the 4.1 will not install from source, in pre-commit. https://github.com/ansible/ansible-lint/issues/590

webknjaz commented 4 years ago

@ssbarnea @awcrosby ^

awcrosby commented 4 years ago

I see this was introduced in #528, the skip logic does not check for a file_type of pre_tasks. #641 was added to fix this.

awcrosby commented 4 years ago

@bvergnaud ansible-lint 4.2.0rc2 has this fix included

bvergnaud commented 4 years ago

Wonderful. Thanks a lot. :)