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

find: explicit empty excludes causes find to exclude everything #70640

Closed
jmazzitelli opened this issue Jul 14, 2020 · 1 comment · Fixed by #70710
Closed

find: explicit empty excludes causes find to exclude everything #70640

jmazzitelli opened this issue Jul 14, 2020 · 1 comment · Fixed by #70710
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. files Files category module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation support:core This issue/PR relates to code supported by the Ansible Engineering Team. verified This issue has been verified/reproduced by maintainer

Comments

@jmazzitelli
Copy link

SUMMARY

When using find with empty excludes list, it excludes everything, yet if you remove that empty excludes entirely, the find behaves correctly (nothing is excluded).

ISSUE TYPE
  • Bug Report
COMPONENT NAME

find

ANSIBLE VERSION
$ ansible --version
ansible 2.9.9
  config file = None
  configured module search path = [u'/home/jmazzite/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/jmazzite/source/ansible/lib/ansible
  executable location = /home/jmazzite/source/ansible/bin/ansible
  python version = 2.7.5 (default, Jun 11 2019, 14:33:56) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
CONFIGURATION

OS / ENVIRONMENT

RHEL 7.7

STEPS TO REPRODUCE

Run find task with excludes: [ ] and see that the results come back empty - everything is excluded. But if you remove that excludes: [ ] then find results come back correctly.

- hosts: localhost
  connection: local
  tasks:
  - find:
      paths: "/etc"
      patterns: ['hosts', 'passwd']
      excludes: []
    register: test
  - debug:
      msg: "number of files found-->{{ test.files | length }}"
  - debug:
      msg: "found-->{{ item.path }}"
    loop: "{{ test.files }}"

Run that playbook via ansible-playbook playbook.yaml and see the results of find is empty - 0 files are returned:

TASK [debug] *****************************************************************************************************************************
ok: [localhost] => {
    "msg": "number of files found-->0"
}

Now edit that playbook and completely delete the excludes: [ ] line and re-run it. Now see it returns the correct two files:

TASK [debug] *****************************************************************************************************************************
ok: [localhost] => {
    "msg": "number of files found-->2"
}

TASK [debug] *****************************************************************************************************************************
ok: [localhost] => (item=...chomp...) => {
    "msg": "found-->/etc/hosts"
}
ok: [localhost] => (item=...chomp...) => {
    "msg": "found-->/etc/passwd"
}

EXPECTED RESULTS

I expect an empty excludes list to behave identically as when excludes list is completely not specified. An empty excludes list should mean, "I do not want to exclude anything".

ACTUAL RESULTS

All files are excluded if I specify an empty list in excludes but this is wrong - that should definitely not mean "I want to exclude EVERYTHING".

@jmazzitelli
Copy link
Author

jmazzitelli commented Jul 14, 2020

The workaround to this is to never set an empty list in excludes: - if you want to exclude nothing, you can either delete the excludes or (if your playbook is using a variable for the list value of excludes and so excludes is always specified) you can set the list to some arbitrary value that you know will never match anything (in my case, setting it to [''] will workaround the issue).

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. files Files category has_pr This issue has an associated PR. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jul 14, 2020
@bcoca bcoca added P3 Priority 3 - Approved, No Time Limitation needs_verified This issue needs to be verified/reproduced by maintainer and removed has_pr This issue has an associated PR. needs_triage Needs a first human triage before being processed. labels Jul 16, 2020
sivel added a commit to sivel/ansible that referenced this issue Jul 17, 2020
@sivel sivel added verified This issue has been verified/reproduced by maintainer and removed needs_verified This issue needs to be verified/reproduced by maintainer labels Jul 17, 2020
@ansible ansible locked and limited conversation to collaborators Aug 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. files Files category module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation support:core This issue/PR relates to code supported by the Ansible Engineering Team. verified This issue has been verified/reproduced by maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants