
##### SUMMARY

The `fileglob` lookup plugin returns values inconsistently, depending on the order of arguments (terms) given it.

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME

fileglob

##### ANSIBLE VERSION

```paste below
ansible 2.10.3
  config file = /Users/jpm/take/training/bugs/fileglob/ansible.cfg
  configured module search path = ['/Users/jpm/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/jpm/take/training/bugs/fileglob/env.v3/lib/python3.8/site-packages/ansible
  executable location = /Users/jpm/take/training/bugs/fileglob/env.v3/bin/ansible
  python version = 3.8.5 (default, Sep 27 2020, 11:38:54) [Clang 12.0.0 (clang-1200.0.32.2)]
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below
ANSIBLE_NOCOWS(/Users/jpm/take/training/bugs/fileglob/ansible.cfg) = True
```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->

macOS Catalina (10.15.7)

##### STEPS TO REPRODUCE

Run the example playbook

```yaml
- hosts: localhost
  connection: local
  gather_facts: false
  vars:
     dir: files
  tasks:
  - file: path='{{ dir }}' state=directory
  
  - file: path='setvars.bat' state=touch  # in current directory!

  - file: path='{{ dir }}/{{ item }}' state=touch
    loop:
        - json.c
        - strlcpy.c
        - base64.c
        - json.h
        - base64.h
        - strlcpy.h
        - jo.c

  - debug:
        msg: '{{ query("fileglob", "setvars.bat", "{{ dir }}/*.[ch]" ) }}'

  - debug:
        msg: '{{ query("fileglob", "{{ dir }}/*.[ch]", "setvars.bat" ) }}'
```


##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->

I expected the path `setvars.bat` to be contained in both result sets, but it's in the first only. The results are identical if I use `lookup()` instead of `query()` and when I use `with_fileglob:`

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes -->
```paste below
PLAY [localhost] ***************************************************************

TASK [file] ********************************************************************
ok: [localhost]

TASK [file] ********************************************************************
changed: [localhost] => (item=json.c)
changed: [localhost] => (item=strlcpy.c)
changed: [localhost] => (item=base64.c)
changed: [localhost] => (item=json.h)
changed: [localhost] => (item=base64.h)
changed: [localhost] => (item=strlcpy.h)
changed: [localhost] => (item=jo.c)

TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": [
        "/Users/jpm/take/training/bugs/fileglob/setvars.bat",
        "/Users/jpm/take/training/bugs/fileglob/files/json.c",
        "/Users/jpm/take/training/bugs/fileglob/files/strlcpy.c",
        "/Users/jpm/take/training/bugs/fileglob/files/base64.h",
        "/Users/jpm/take/training/bugs/fileglob/files/json.h",
        "/Users/jpm/take/training/bugs/fileglob/files/base64.c",
        "/Users/jpm/take/training/bugs/fileglob/files/strlcpy.h",
        "/Users/jpm/take/training/bugs/fileglob/files/jo.c"
    ]
}

TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": [
        "/Users/jpm/take/training/bugs/fileglob/files/json.c",
        "/Users/jpm/take/training/bugs/fileglob/files/strlcpy.c",
        "/Users/jpm/take/training/bugs/fileglob/files/base64.h",
        "/Users/jpm/take/training/bugs/fileglob/files/json.h",
        "/Users/jpm/take/training/bugs/fileglob/files/base64.c",
        "/Users/jpm/take/training/bugs/fileglob/files/strlcpy.h",
        "/Users/jpm/take/training/bugs/fileglob/files/jo.c"
    ]
}

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
```

- Patterns are only supported on files, not directory/paths.
      - Matching is against local system files on the Ansible controller.
        To iterate a list of files on a remote node, use the M(ansible.builtin.find) module.
      - Returns a string list of paths joined by commas, or an empty list if no files match. For a 'true list' pass C(wantlist=True) to the lookup.
"""
EXAMPLES = """
- name: Display paths of all .txt files in dir
  debug: msg={{ lookup('fileglob', '/my/path/*.txt') }}
- name: Copy each file over that matches the given pattern
  copy:
    src: "{{ item }}"
    dest: "/etc/fooapp/"
    owner: "root"
    mode: 0600
  with_fileglob:
    - "/playbooks/files/fooapp/*"
"""
RETURN = """
  _list:
    description:
      - list of files
    type: list
    elements: path
"""
import os
import glob
from ansible.plugins.lookup import LookupBase
from ansible.errors import AnsibleFileNotFound
from ansible.module_utils._text import to_bytes, to_text
class LookupModule(LookupBase):