### Summary

I obtain a error with include_vars when the input folder was created by ``tempfile`` instead of ``file``

````
TASK [load inventories into variable] *********************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'failed' referenced before assignment
fatal: [master]: FAILED! => {"msg": "Unexpected failure during module execution.", "stdout": ""}
````

but if I use this instead it will works
````
    - name: create temp folder
      file:
        path: /tmp/ansible-inventory-sources
        state: directory
      register: tmp_folder
````
the result
````
TASK [load inventories into variable] *********************************************************************************************************************
ok: [master] => {"ansible_facts": {"stuff": {"all": {"children": {"masters": {"hosts": {"master": {"ansible_connection": "local", "ansible_host": "192.168.51.180", "domain": "clustervagrant.dynamic.local", "fqdn": "ns1.clustervagrant.local"}}}, "workers": {"hosts": {"worker1": {"ansible_host": "192.168.51.181"}}, "vars": {"ansible_connection": "ssh", "ansible_ssh_pass": "vagrant", "ansible_ssh_user": "vagrant", "ansible_sudo_pass": "vagrant"}}}}, "coucou": {"allo": true}}}, "ansible_included_var_files": ["/tmp/ansible-inventory-sources/inventory-test", "/tmp/ansible-inventory-sources/inventory-vagrant"], "changed": false}

PLAY RECAP ************************************************************************************************************************************************
master                     : ok=8    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

````


### Issue Type

Bug Report

### Component Name

include_vars

### Ansible Version

```console
$ ansible --version
vagrant@k8s-master:/vagrant/test-templates$ ansible --version
ansible [core 2.12.1]
  config file = /vagrant/test-templates/ansible.cfg
  configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.5 (default, May 27 2021, 13:30:53) [GCC 9.3.0]
  jinja version = 2.10.1
  libyaml = True
vagrant@k8s-master:/vagrant/test-templates$
```


### Configuration

```console
$ ansible-config dump --only-changed
vagrant@k8s-master:/vagrant/test-templates/inventory$ ansible-config dump --only-changed
vagrant@k8s-master:/vagrant/test-templates/inventory$
```


### OS / Environment

````
vagrant@k8s-master:/vagrant/test-templates/inventory$ uname -a
Linux k8s-master 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
vagrant@k8s-master:/vagrant/test-templates/inventory$
````

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml 

---
- hosts: "masters"
  become: yes
  become_method: sudo
  become_user: root
  gather_facts: yes
  connection: ssh

  tasks:
    - name: debug through ansible.env
      debug: var=ansible_env.HOME

    - name: debug through ansible.env
      debug: var=ansible_inventory_sources


    - name: create temp folder
      tempfile:
        path: /tmp
        prefix: ansible-inventory
        state: directory
      register: tmp_folder

# WORKS IF I USE THIS BELLOW TO CREATE THE FOLDER
#    - name: create temp folder  
#      file:
#        path: /tmp/ansible-inventory-sources
#        state: directory
#      register: tmp_folder

    - name: tmp_folder
      debug: var=tmp_folder

    - name: create temp folder structure
      shell: mkdir -p $(dirname '{{tmp_folder.path}}{{item}}')
      with_items:
        - "{{ansible_inventory_sources}}"

    - name: file inventory used into tmp folder
      copy:
        src: "{{item}}"
        dest: "{{tmp_folder.path}}"
      with_items:
        - "{{ansible_inventory_sources}}"

    - name: load inventories into variable
      include_vars:
        dir: "{{tmp_folder.path}}"
        ignore_unknown_extensions: no
        extensions:
          - ''
          - 'yaml'
          - 'yml'
          - 'json'
        name: stuff
```


### Expected Results

I expect the get the same result for **include_vars** is a use a folder created by ``file`` or ``tempfile``
````
   - name: create temp folder
      file:
        path: /tmp/ansible-inventory-sources
        state: directory
      register: tmp_folder

    - name: tmp_folder
      debug: var=tmp_folder

    - name: create temp folder structure
      shell: mkdir -p $(dirname '{{tmp_folder.path}}{{item}}')
      with_items:
        - "{{ansible_inventory_sources}}"

    - name: file inventory used into tmp folder
      copy:
        src: "{{item}}"
        dest: "{{tmp_folder.path}}"
      with_items:
        - "{{ansible_inventory_sources}}"

    - name: load inventories into variable
      include_vars:
        dir: "{{tmp_folder.path}}"
        ignore_unknown_extensions: no
        extensions:
          - ''
          - 'yaml'
          - 'yml'
          - 'json'
        name: stuff

````

the output
````
vagrant@k8s-master:/vagrant/test-templates$ ansible-playbook -i inventory/inventory-vagrant -i inventory/inventory-test playbooks/test-playbook.yaml -v
Using /vagrant/test-templates/ansible.cfg as config file
[WARNING]: Skipping key (allo) in group (coucou) as it is not a mapping, it is a <class 'bool'>

PLAY [masters] ********************************************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************************************************
ok: [master]

TASK [debug through ansible.env] **************************************************************************************************************************
ok: [master] => {
    "ansible_env.HOME": "/root"
}

TASK [debug through ansible.env] **************************************************************************************************************************
ok: [master] => {
    "ansible_inventory_sources": [
        "/vagrant/test-templates/inventory/inventory-vagrant",
        "/vagrant/test-templates/inventory/inventory-test"
    ]
}

TASK [create temp folder] *********************************************************************************************************************************
changed: [master] => {"changed": true, "gid": 0, "group": "root", "mode": "0755", "owner": "root", "path": "/tmp/ansible-inventory-sources", "size": 4096, "state": "directory", "uid": 0}

TASK [tmp_folder] *****************************************************************************************************************************************
ok: [master] => {
    "tmp_folder": {
        "changed": true,
        "diff": {
            "after": {
                "path": "/tmp/ansible-inventory-sources",
                "state": "directory"
            },
            "before": {
                "path": "/tmp/ansible-inventory-sources",
                "state": "absent"
            }
        },
        "failed": false,
        "gid": 0,
        "group": "root",
        "mode": "0755",
        "owner": "root",
        "path": "/tmp/ansible-inventory-sources",
        "size": 4096,
        "state": "directory",
        "uid": 0
    }
}

TASK [create temp folder structure] ***********************************************************************************************************************
changed: [master] => (item=/vagrant/test-templates/inventory/inventory-vagrant) => {"ansible_loop_var": "item", "changed": true, "cmd": "mkdir -p $(dirname '/tmp/ansible-inventory-sources/vagrant/test-templates/inventory/inventory-vagrant')", "delta": "0:00:00.012595", "end": "2022-01-11 16:10:00.823954", "item": "/vagrant/test-templates/inventory/inventory-vagrant", "msg": "", "rc": 0, "start": "2022-01-11 16:10:00.811359", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
changed: [master] => (item=/vagrant/test-templates/inventory/inventory-test) => {"ansible_loop_var": "item", "changed": true, "cmd": "mkdir -p $(dirname '/tmp/ansible-inventory-sources/vagrant/test-templates/inventory/inventory-test')", "delta": "0:00:00.010872", "end": "2022-01-11 16:10:01.163583", "item": "/vagrant/test-templates/inventory/inventory-test", "msg": "", "rc": 0, "start": "2022-01-11 16:10:01.152711", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

TASK [file inventory used into tmp folder] ****************************************************************************************************************
changed: [master] => (item=/vagrant/test-templates/inventory/inventory-vagrant) => {"ansible_loop_var": "item", "changed": true, "checksum": "8619f133048a1c3b62b02c25f974c19c763c144c", "dest": "/tmp/ansible-inventory-sources/inventory-vagrant", "gid": 0, "group": "root", "item": "/vagrant/test-templates/inventory/inventory-vagrant", "md5sum": "bd85cb52626fe2517fbc5aa988acf023", "mode": "0644", "owner": "root", "size": 474, "src": "/home/vagrant/.ansible/tmp/ansible-tmp-1641917401.2987561-334984-181990277684472/source", "state": "file", "uid": 0}
changed: [master] => (item=/vagrant/test-templates/inventory/inventory-test) => {"ansible_loop_var": "item", "changed": true, "checksum": "bbc1139b095a847fb831b5d128bdeb98104b694b", "dest": "/tmp/ansible-inventory-sources/inventory-test", "gid": 0, "group": "root", "item": "/vagrant/test-templates/inventory/inventory-test", "md5sum": "3bd6b415977f647d3f288bef952d9003", "mode": "0644", "owner": "root", "size": 231, "src": "/home/vagrant/.ansible/tmp/ansible-tmp-1641917402.7306056-334984-106388615338814/source", "state": "file", "uid": 0}

TASK [load inventories into variable] *********************************************************************************************************************
ok: [master] => {"ansible_facts": {"stuff": {"all": {"children": {"masters": {"hosts": {"master": {"ansible_connection": "local", "ansible_host": "192.168.51.180", "domain": "clustervagrant.dynamic.local", "fqdn": "ns1.clustervagrant.local"}}}, "workers": {"hosts": {"worker1": {"ansible_host": "192.168.51.181"}}, "vars": {"ansible_connection": "ssh", "ansible_ssh_pass": "vagrant", "ansible_ssh_user": "vagrant", "ansible_sudo_pass": "vagrant"}}}}, "coucou": {"allo": true}}}, "ansible_included_var_files": ["/tmp/ansible-inventory-sources/inventory-test", "/tmp/ansible-inventory-sources/inventory-vagrant"], "changed": false}

PLAY RECAP ************************************************************************************************************************************************
master                     : ok=8    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0


````

### Actual Results

```console
`
...
TASK [load inventories into variable] *********************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'failed' referenced before assignment
fatal: [master]: FAILED! => {"msg": "Unexpected failure during module execution.", "stdout": ""}
````
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct
if current_depth <= self.depth or self.depth == 0:
                current_files.sort()
                yield (current_root, current_files)
            else:
                break
    def _ignore_file(self, filename):
        """ Return True if a file matches the list of ignore_files.
        Args:
            filename (str): The filename that is being matched against.
        Returns:
            Boolean
        """
        for file_type in self.ignore_files:
            try:
                if re.search(r'{0}$'.format(file_type), filename):
                    return True
            except Exception:
                err_msg = 'Invalid regular expression: {0}'.format(file_type)
                raise AnsibleError(err_msg)
        return False
    def _is_valid_file_ext(self, source_file):
        """ Verify if source file has a valid extension
        Args:
            source_file (str): The full path of source file or source file.
        Returns:
            Bool
        """
        file_ext = path.splitext(source_file)
        return bool(len(file_ext) > 1 and file_ext[-1][1:] in self.valid_extensions)
    def _load_files(self, filename, validate_extensions=False):