# Use dynamic inventory with windows ec2

**URL:** <https://forum.ansible.com/t/use-dynamic-inventory-with-windows-ec2/23016>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [November 14, 2016, 1:30am UTC](https://forum.ansible.com/t/use-dynamic-inventory-with-windows-ec2/23016 "2016-11-14T01:30:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![challa.tek](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@challa.tek](https://forum.ansible.com/u/challa.tek)\
**Post date:** [November 14, 2016, 1:30am UTC](https://forum.ansible.com/t/use-dynamic-inventory-with-windows-ec2/23016/1 "2016-11-14T01:30:36Z")

</div>

Can any one suggest me with best way for using dynamic inventory for ec2 windows.  
Usually for linux ec2…i have a play which goes like

1. creates a ec2 instance —first play
2. refresh dynamic inventory —2nd play
3. connect to linux instance --3rd play

but when i do the same thing with windows ec2…ansible is trying to ssh into the windows host and failing…

can any one post a sample play that i can use to create ec2 windows,refresh dynamic inventory and connect and configure the windows in the same playbook without having to create a static inventory for windows.

---

<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:** [November 14, 2016, 10:40am UTC](https://forum.ansible.com/t/use-dynamic-inventory-with-windows-ec2/23016/2 "2016-11-14T10:40:27Z")

</div>

I don’t have any examples but I think you could have a static group\_vars/windows.yml file that sets the windows connection settings and then add\_host the windows instance(s) to your pre-existing static windows group.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [November 14, 2016, 4:47pm UTC](https://forum.ansible.com/t/use-dynamic-inventory-with-windows-ec2/23016/3 "2016-11-14T16:47:30Z")

</div>

Yep, that’s exactly what we tell folks to do. You can also use a conditional meta: refresh\_inventory with the same technique (and map the tag-based groups into “human-readable” group names in the static inventory) when the task returns new hosts created instead of the add\_host. That way you don’t have to worry about dynamically mapping groups in your playbook- you can keep it all abstracted in the inventory. Functionally about the same…

-Matt

---

<div class="post-metadata">

**Author:** ![Bryan\_Banks](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@Bryan\_Banks](https://forum.ansible.com/u/Bryan_Banks)\
**Post date:** [February 7, 2017, 10:39pm UTC](https://forum.ansible.com/t/use-dynamic-inventory-with-windows-ec2/23016/4 "2017-02-07T22:39:40Z")

</div>

Hi, I’m sorry to bring up an old thread but could you show an example of how you would go about doing this? My goal is to use dynamic inventory with Windows EC2 instances (works fine with linux)
