### Summary

Hi,

Since Ansible 8, when multiple roles include the same dependency and when the first role doesn't run because of a `when` condition, then the dependency is not included at all.

### Issue Type

Bug Report

### Component Name

role

### Ansible Version

```console
ansible [core 2.15.2]
  config file = /home/courgette/Documents/Bimdata/dev/deployment/ansible.cfg
  configured module search path = ['/home/courgette/Documents/Bimdata/dev/deployment/library', '/home/courgette/Documents/Bimdata/dev/deployment/kubespray/library']
  ansible python module location = /home/courgette/.virtualenvs/deploy/lib/python3.11/site-packages/ansible
  ansible collection location = /home/courgette/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/courgette/.virtualenvs/deploy/bin/ansible
  python version = 3.11.3 (main, Jun  5 2023, 09:32:32) [GCC 13.1.1 20230429] (/home/courgette/.virtualenvs/deploy/bin/python)
  jinja version = 3.1.2
  libyaml = True
```


### Configuration

```console
CONFIG_FILE() = /home/courgette/Documents/Bimdata/dev/deployment/ansible.cfg
DEFAULT_FILTER_PLUGIN_PATH(/home/courgette/Documents/Bimdata/dev/deployment/ansible.cfg) = ['/home/courgette/Documents/Bimdata/dev/deployment/ansible_plugins/filter_plugins']
DEFAULT_TIMEOUT(/home/courgette/Documents/Bimdata/dev/deployment/ansible.cfg) = 60
DEFAULT_VAULT_PASSWORD_FILE(/home/courgette/Documents/Bimdata/dev/deployment/ansible.cfg) = /home/courgette/Documents/Bimdata/dev/deployment/.get-vault-pass.sh
EDITOR(env: EDITOR) = vim
PAGER(env: PAGER) = less

CONNECTION:
==========

paramiko_ssh:
____________
timeout(/home/courgette/Documents/Bimdata/dev/deployment/ansible.cfg) = 60

ssh:
___
pipelining(/home/courgette/Documents/Bimdata/dev/deployment/ansible.cfg) = True
timeout(/home/courgette/Documents/Bimdata/dev/deployment/ansible.cfg) = 60
```


### OS / Environment

Archlinux

### Steps to Reproduce

- Create a file `roles/test_a/tasks/main.yml` with:
```
---
- name: "Debug."
  ansible.builtin.debug:
    msg: "test_a"
```
- Create a file `roles/test_b/meta/main.yml` with:
```
 ---
dependencies:
  - role: test_a
 ```

- Create a file `roles/test_b/tasks/main.yml` with:
```
---
- name: "Debug."
  ansible.builtin.debug:
    msg: "test_b
```

- Duplicate test_b into test_c: `cp -r roles/test_b roles/test_c`
- Modify the debug message of the test_c role: `sed -i 's/test_b/test_c/g' roles/test_c/tasks/main.yml`

- Create the file `test.yml` with:
```
---
- name: Test
  hosts: localhost
  gather_facts: false
  become: false
  vars:
    skip_b: true
    skip_c: false
  roles:
    - role: test_b
      when: not skip_b
    - role: test_c
      when: not skip_c
```

- Run : `ansible-playbook test.yml`

### Expected Results

I expected test_a to be include by test_c, but I was chocked that it did not.

It's working fine with Ansible 7. For reference, here the complete version of ansible 7 that I use, and the corresponding output.
```
ansible [core 2.14.8]
  config file = /home/courgette/Documents/Bimdata/dev/deployment/ansible.cfg
  configured module search path = ['/home/courgette/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/courgette/.virtualenvs/deploy/lib/python3.11/site-packages/ansible
  ansible collection location = /home/courgette/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/courgette/.virtualenvs/deploy/bin/ansible
  python version = 3.11.3 (main, Jun  5 2023, 09:32:32) [GCC 13.1.1 20230429] (/home/courgette/.virtualenvs/deploy/bin/python)
  jinja version = 3.1.2
  libyaml = True
```

```
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Test] *********************************************************************************************************************************************************************************************************

TASK [test_a : Debug.] **********************************************************************************************************************************************************************************************
skipping: [localhost]

TASK [test_b : Debug.] **********************************************************************************************************************************************************************************************
skipping: [localhost]

TASK [test_a : Debug.] **********************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "test_a"
}

TASK [test_c : Debug.] **********************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "test_c"
}

PLAY RECAP **********************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=2    rescued=0    ignored=0   

```

### Actual Results

```console
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Test] *********************************************************************************************************************************************************************************************************

TASK [test_a : Debug.] **********************************************************************************************************************************************************************************************
skipping: [localhost]

TASK [test_b : Debug.] **********************************************************************************************************************************************************************************************
skipping: [localhost]

TASK [test_c : Debug.] **********************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "test_c"
}

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


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct
self._set_hosts_cache(play, refresh=False)
        return [host for host in self._hosts_cache if host in self._tqm._failed_hosts]
    def add_tqm_variables(self, vars, play):
        '''
        Base class method to add extra variables/information to the list of task
        vars sent through the executor engine regarding the task queue manager state.
        '''
        vars['ansible_current_hosts'] = self.get_hosts_remaining(play)
        vars['ansible_failed_hosts'] = self.get_failed_hosts(play)
    def _queue_task(self, host, task, task_vars, play_context):
        ''' handles queueing the task up to be sent to a worker '''
        display.debug("entering _queue_task() for %s/%s" % (host.name, task.action))
        
        
        
        
        
        
        
        
        
        
        if task.action not in action_write_locks.action_write_locks:
            display.debug('Creating lock for %s' % task.action)
            action_write_locks.action_write_locks[task.action] = Lock()
        
        templar = Templar(loader=self._loader, variables=task_vars)
        try: