# Using facts in 'tasks\_from' with 'include\_role' will load the same task file for all hosts.

**URL:** <https://forum.ansible.com/t/using-facts-in-tasks-from-with-include-role-will-load-the-same-task-file-for-all-hosts/44204>\
**Category:** Get Help\
**Tags:** windows, role, facts\
**Created:** [August 5, 2025, 3:52am UTC](https://forum.ansible.com/t/using-facts-in-tasks-from-with-include-role-will-load-the-same-task-file-for-all-hosts/44204 "2025-08-05T03:52:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlos.e](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/carlos.e/32/9238_2.png) [@carlos.e](https://forum.ansible.com/u/carlos.e)\
**Post date:** [August 5, 2025, 3:52am UTC](https://forum.ansible.com/t/using-facts-in-tasks-from-with-include-role-will-load-the-same-task-file-for-all-hosts/44204/1 "2025-08-05T03:52:53Z")

</div>

I was trying to use different entry points for a role depending on `ansible_facts['system']` var.

The following example role has only 2 task files:

`Linux.yml`:

```yaml
---
- name: Assert
  ansible.builtin.assert:
    that:
      - ansible_facts['system'] == 'Linux'
...

```

`Win32NT.yml`:

```yaml
---
- name: Assert
  ansible.builtin.assert:
    that:
      - ansible_facts['system'] == 'Win32NT'
...

```

Playbook `test1.yml`:

```yaml
---
- name: Play
  hosts: all
  tasks:
    - name: Include role
      ansible.builtin.include_role:
        name: test
        tasks_from: "{{ ansible_facts['system'] }}"
...

```

Lets say we have a Windows host named `win1`, and a Linux host named `lin1`

The problem only occurs when you mix Windows and Linux hosts in the same run:

```bash
ansible-playbook test1.yml -l 'win1,lin1'

```

```auto
PLAY [Play] *********************************************************************************************************************************

TASK [Include role] *************************************************************************************************************************
included: test for lin1, win1

TASK [test : Assert] ************************************************************************************************************************
ok: [lin1] => 
    changed: false
    msg: All assertions passed
[ERROR]: Task failed: Action failed: Assertion failed
Origin: /home/carlos/repos/vfmsa_roles/roles/test/tasks/Linux.yml:2:3

1 ---
2 - name: Assert
    ^ column 3

fatal: [win1]: FAILED! => 
    assertion: ansible_facts['system'] == 'Linux'
    changed: false
    evaluated_to: false
    msg: Assertion failed

PLAY RECAP **********************************************************************************************************************************
lin1 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0   
win1 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0   

```

Ansible is using `Linux.yml` for all hosts.

There are no issues when running the playbook with each host independently.

Is what I’m trying to do _legal_? If not: why?

Ansible version: `2.19.0`  
The same problem occurs with `2.18`

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [August 5, 2025, 2:02pm UTC](https://forum.ansible.com/t/using-facts-in-tasks-from-with-include-role-will-load-the-same-task-file-for-all-hosts/44204/2 "2025-08-05T14:02:11Z")

</div>

I believe we have a bug report detailing this already:

> <https://github.com/ansible/ansible/issues/66497>
>
> \##### SUMMARY
> 
> We're trying to implement roles, which can be individualized by… supplying host related vars files. This doesn't seem to work under certain circumstances. Up to now we're not yet sure, whether this is a bug or works as designed.
> \##### ISSUE TYPE
> \- Bug Report
> 
> \##### COMPONENT NAME
> 
> include\_role
> \##### ANSIBLE VERSION
> 
> \`\`\`paste below
> ansible 2.9.9
> config file = /adm/afroebel/ansible/unix/ansible.cfg
> configured module search path = \[u'/adm/afroebel/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'\]
> ansible python module location = /usr/lib/python2.7/dist-packages/ansible
> executable location = /usr/bin/ansible
> python version = 2.7.16 (default, Oct 10 2019, 22:02:15) \[GCC 8.3.0\]
> \`\`\`
> 
> \##### CONFIGURATION
> 
> \`\`\`paste below
> DEFAULT\_GATHERING(/adm/afroebel/ansible/unix/ansible.cfg) = explicit
> DEFAULT\_MANAGED\_STR(/adm/afroebel/ansible/unix/ansible.cfg) = {file}
> DEFAULT\_PRIVATE\_ROLE\_VARS(/adm/afroebel/ansible/unix/ansible.cfg) = True
> PERSISTENT\_CONNECT\_TIMEOUT(/adm/afroebel/ansible/unix/ansible.cfg) = 30
> \`\`\`
> 
> \##### OS / ENVIRONMENT
> 
> Ansible controller: Debian GNU/Linux 10
> managed devices: Oracle Solaris 11.3/11.4
> 
> \##### STEPS TO REPRODUCE
> 
> We've got 3 simple roles with exactly the same content, one task file and two vars files named like ansible hosts:
> 
> 
> \`\`\`yaml
> \# cksum test/roles/test\_role/\*/\*/\*
> 201185725 22 test/roles/test\_role/solaris/tasks/main.yml
> 1196793317 19 test/roles/test\_role/solaris/vars/test07
> 2721971076 19 test/roles/test\_role/solaris/vars/test08
> 201185725 22 test/roles/test\_role/test07/tasks/main.yml
> 1196793317 19 test/roles/test\_role/test07/vars/test07
> 2721971076 19 test/roles/test\_role/test07/vars/test08
> 201185725 22 test/roles/test\_role/test08/tasks/main.yml
> 1196793317 19 test/roles/test\_role/test08/vars/test07
> 2721971076 19 test/roles/test\_role/test08/vars/test08
> 
> \# cat test/roles/test\_role/solaris/tasks/main.yml
> \---
> \- debug: var=var1
> 
> \# cat test/roles/test\_role/solaris/vars/test07
> \---
> var1: "test07"
> 
> \# cat test/roles/test\_role/solaris/vars/test08
> \---
> var1: "test08"
> \`\`\`
> We now executed the playbook test/include\_role.yml:
> \`\`\`yaml
> \---
> \- name: "Test Playbook"
> hosts: "test07:test08"
> tasks:
> - include\_role:
> name: "test\_role/{{ inventory\_hostname\_short}}"
> vars\_from: "{{ inventory\_hostname\_short }}"
> \`\`\`
> It worked well and produced the following output:
> \`\`\`yaml
> \# ansible-playbook -i inventory test/include\_role.yml
> 
> PLAY \[Test Playbook\] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> TASK \[include\_role : test\_role/{{ inventory\_hostname\_short}}\] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> TASK \[test\_role/test07 : debug\] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> ok: \[test07\] =\> {
> "var1": "test07"
> }
> 
> TASK \[test\_role/test08 : debug\] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> ok: \[test08\] =\> {
> "var1": "test08"
> }
> 
> PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> test07: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
> test08: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
> \`\`\`
> Tracing the ansible-playbook command using strace revealed, that tasks and vars files of either role were actually opened and read from.
> 
> The playbook test/include\_role.yml was slightly changed in order to include a generic role test\_role/solaris instead of the host related roles.
> \`\`\`yaml
> \---
> \- name: "Test Playbook"
> hosts: "test07:test08"
> tasks:
> - include\_role:
> name: "test\_role/solaris"
> vars\_from: "{{ inventory\_hostname\_short }}"
> \`\`\`
> 
> 
> \##### EXPECTED RESULTS
> 
> As the content of the generic role was exactly the same as the content of the host related roles, we would expect the playbook to produce the same output.
> 
> \##### ACTUAL RESULTS
> 
> Even though the host related vars files contained different values for variable var1, ansible only used one of them during execution.
> 
> \`\`\`yaml
> \# ansible-playbook -i inventory test/include\_role.yml
> 
> PLAY \[Test Playbook\] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> TASK \[include\_role : test\_role/solaris\] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> TASK \[test\_role/solaris : debug\] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> ok: \[test07\] =\> {
> "var1": "test07"
> }
> ok: \[test08\] =\> {
> "var1": "test07"
> }
> 
> PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> test07: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
> test08: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
> \`\`\`
> Tracing the ansible-playbook command using strace revealed, that this time only vars file test07 was opened and read from.

---

<div class="post-metadata">

**Author:** ![carlos.e](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/carlos.e/32/9238_2.png) [@carlos.e](https://forum.ansible.com/u/carlos.e)\
**Post date:** [August 5, 2025, 9:25pm UTC](https://forum.ansible.com/t/using-facts-in-tasks-from-with-include-role-will-load-the-same-task-file-for-all-hosts/44204/3 "2025-08-05T21:25:28Z")

</div>

> [@sivel](#):
>
> I believe we have a bug report detailing this already:

I’m not completely sure is the same problem. But anyway, that was supposed to be fixed 3 years ago.

What I want to know first is how to approach this. Is this a known bug? Am I doing something out of best practices? Is it just me? Can someone reproduce it? Should I open a bug report?

---

<div class="post-metadata">

**Author:** ![mkrizek](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mkrizek/32/2055_2.png) [@mkrizek](https://forum.ansible.com/u/mkrizek)\
**Post date:** [August 6, 2025, 12:17pm UTC](https://forum.ansible.com/t/using-facts-in-tasks-from-with-include-role-will-load-the-same-task-file-for-all-hosts/44204/4 "2025-08-06T12:17:30Z")

</div>

As it was already mentioned, yes, it is a known bug reported in a still open issue: [include\_role sometimes ignores dynamic vars\_from parameter · Issue #66497 · ansible/ansible · GitHub](https://github.com/ansible/ansible/issues/66497)

The bug manifests itself on all `*_from` options. The bug above specifically mentions `vars_from` in its title but it applies to `tasks_from` too as you are seeing in your playbook.

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [August 7, 2025, 2:43pm UTC](https://forum.ansible.com/t/using-facts-in-tasks-from-with-include-role-will-load-the-same-task-file-for-all-hosts/44204/5 "2025-08-07T14:43:34Z")

</div>

[IncludedFile: store \_from args for proper deduplication by mkrizek · Pull Request #85628 · ansible/ansible · GitHub](https://github.com/ansible/ansible/pull/85628) and here is fix

---

<div class="post-metadata">

**Author:** ![carlos.e](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/carlos.e/32/9238_2.png) [@carlos.e](https://forum.ansible.com/u/carlos.e)\
**Post date:** [August 7, 2025, 3:22pm UTC](https://forum.ansible.com/t/using-facts-in-tasks-from-with-include-role-will-load-the-same-task-file-for-all-hosts/44204/6 "2025-08-07T15:22:57Z")

</div>

Awsome!

That did the trick. thank you.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 6, 2025, 3:23pm UTC](https://forum.ansible.com/t/using-facts-in-tasks-from-with-include-role-will-load-the-same-task-file-for-all-hosts/44204/7 "2025-09-06T15:23:07Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
