# Importing OS-specific variables

**URL:** <https://forum.ansible.com/t/importing-os-specific-variables/4285>\
**Category:** Get Help\
**Created:** [March 9, 2024, 1:38pm UTC](https://forum.ansible.com/t/importing-os-specific-variables/4285 "2024-03-09T13:38:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zoliky](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/zoliky/32/2507_2.png) [@zoliky](https://forum.ansible.com/u/zoliky)\
**Post date:** [March 9, 2024, 1:38pm UTC](https://forum.ansible.com/t/importing-os-specific-variables/4285/1 "2024-03-09T13:38:32Z")

</div>

Hello,  
I want Ansible to examine the `vars` folder, and even if it’s empty or doesn’t contain a `default.yml` file, I don’t want it to fail. I’ve tried the following code, but it doesn’t seem to be working. Do you have any ideas on what I might be doing wrong?

tasks/main.yml:

```auto
---
- name: Include OS-specific variables
  ansible.builtin.include_vars: "{{ lookup('ansible.builtin.first_found', params) }}"
  vars:
    params:
      files:
        - "{{ ansible_distribution | lower }}.yml"
        - "{{ ansible_os_family | lower }}.yml"
        - default.yml
      paths:
        - "vars"
      skip: true
  when: params | length > 0

```

I would be grateful for any suggestion. Thank you.

Zoltan

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [March 9, 2024, 3:32pm UTC](https://forum.ansible.com/t/importing-os-specific-variables/4285/2 "2024-03-09T15:32:45Z")

</div>

Are you looking for `ignore_errors: true`? [Error handling in playbooks — Ansible Documentation](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html)

---

<div class="post-metadata">

**Author:** ![zoliky](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/zoliky/32/2507_2.png) [@zoliky](https://forum.ansible.com/u/zoliky)\
**Post date:** [March 9, 2024, 3:36pm UTC](https://forum.ansible.com/t/importing-os-specific-variables/4285/3 "2024-03-09T15:36:46Z")

</div>

Thank you. I haven’t tried it, but it doesn’t seem to be the most elegant solution. Normally, the task shouldn’t even run if it doesn’t find a file. That’s why I would have preferred using ‘when’ in this case.

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [March 9, 2024, 3:47pm UTC](https://forum.ansible.com/t/importing-os-specific-variables/4285/4 "2024-03-09T15:47:17Z")

</div>

Oh, I took `I don't want it to fail` as in you wanted it to keep going regardless whether it was there or not.

I don’t think you can do a `when` using variables defined in the same task.

Perhaps do a check on the files (`ansible.builtin.stat`) as a separate task before, and use the results of that for your `when` statement here?

So the logic would be:

1. task 1 runs `ansible.builtin.stat` to check for file(s) and register result
2. task 2 is above with when task 1 sees file(s)

---

<div class="post-metadata">

**Author:** ![zoliky](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/zoliky/32/2507_2.png) [@zoliky](https://forum.ansible.com/u/zoliky)\
**Post date:** [March 9, 2024, 3:53pm UTC](https://forum.ansible.com/t/importing-os-specific-variables/4285/5 "2024-03-09T15:53:05Z")

</div>

Thank you. Then I think it would be easier to include a ‘default.yml’ as a fallback in the ‘vars’ folder, even if it’s empty, and do this for each role.
