# Targeting Windows & Linux Machines from One Role

**URL:** <https://forum.ansible.com/t/targeting-windows-linux-machines-from-one-role/25571>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [September 21, 2017, 9:31pm UTC](https://forum.ansible.com/t/targeting-windows-linux-machines-from-one-role/25571 "2017-09-21T21:31:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Heather\_Luna](https://avatars.discourse-cdn.com/v4/letter/h/5e9695/32.png) [@Heather\_Luna](https://forum.ansible.com/u/Heather_Luna)\
**Post date:** [September 21, 2017, 9:31pm UTC](https://forum.ansible.com/t/targeting-windows-linux-machines-from-one-role/25571/1 "2017-09-21T21:31:53Z")

</div>

I currently have a role that I am trying to tailor to install a splunk forwarder on both Linux and Windows machines but I’m a little confused as to how I should be telling the main.yml to yes go target these other two tasks splunklinux.yml if it’s a RedHat Linux distribution or go to splunkwindows.yml to target Windows.

I found the following logic:

when: ansible\_os\_family == “Windows”

when: ansible\_distribution == “RedHat”

But I’m unclear of whether this is the correct approach or not and also whether or not I need to provide further logic so Ansible knows that yes this machine is a windows machine or this machine is a linux machine. I’d rather keep it all under one role if I can.

Thoughts?

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [September 21, 2017, 10:09pm UTC](https://forum.ansible.com/t/targeting-windows-linux-machines-from-one-role/25571/2 "2017-09-21T22:09:05Z")

</div>

In your main.yml put in include\_tasks: windows.yml when the host is Windows and include\_tasks: unix.yml when it is not. You can use the gathered facts to do this or you can have a variable that can be set when running on Windows by the end user.

Personally I think you should still split the role into 2, Windows is really not interoperable with the Unix side and they use their own modules. You would get quite a large and messy role when trying to handle both and it could become quite complex when implementing and documenting features that one supports and the other doesn’t. I had a lot of success doing this previously where there would be a java role and I would create a win-java role which tried to implement the same functionality where I could.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [September 22, 2017, 2:40pm UTC](https://forum.ansible.com/t/targeting-windows-linux-machines-from-one-role/25571/3 "2017-09-22T14:40:55Z")

</div>

I’d back this up I have win- roles and linux- roles

Bear in mind you can run multiple plays in one playbook, targeting different host groups. Also since a linux host isn’t ever also a windows host you can probably run playbooks in parallel, even if they are installing the same ‘thing’ such as the splunk forwarder.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Heather\_Luna](https://avatars.discourse-cdn.com/v4/letter/h/5e9695/32.png) [@Heather\_Luna](https://forum.ansible.com/u/Heather_Luna)\
**Post date:** [September 22, 2017, 5:17pm UTC](https://forum.ansible.com/t/targeting-windows-linux-machines-from-one-role/25571/4 "2017-09-22T17:17:40Z")

</div>

Thank you! 🙂

---

<div class="post-metadata">

**Author:** ![Heather\_Luna](https://avatars.discourse-cdn.com/v4/letter/h/5e9695/32.png) [@Heather\_Luna](https://forum.ansible.com/u/Heather_Luna)\
**Post date:** [September 22, 2017, 5:17pm UTC](https://forum.ansible.com/t/targeting-windows-linux-machines-from-one-role/25571/5 "2017-09-22T17:17:49Z")

</div>

Thank you! 🙂
