How do you use ec2 dynamic inventory with windows instances?

898 views
Skip to first unread message

Daniel Furze

unread,
Mar 5, 2015, 9:06:10 AM3/5/15
to ansible...@googlegroups.com
I've been playing with ansible and have everything working for managing linux instances via dynamic inventory in ec2, I have also set up windows support when using a fix hosts file.

When I try to use ec2 dynamic inventory to manage windows instances it seems to flip back to trying SSH for access.

Currently I have a simple playbook:

---
### Setup instances

- name: configure iis servers
  hosts: tag_environment_test:&tag_type_iisserver
  roles:
    - iisserver 

in my roles file:

---
### Install iis

- name: Install iis
  win_feature:
    name: "Web-Server"
state: absent
restart: yes
include_sub_features: yes
include_management_tools: yes

ec2 dynamic inventory is managed by boto
wndows credentials are in group_vars/windows.yml

I'm guessing there's a setting for the playbook to tell a role it should use the windows credentials.

Daniel Furze

unread,
Mar 5, 2015, 12:25:15 PM3/5/15
to ansible...@googlegroups.com
doh!

I solved it by creating a group_vars file with the same name as one of my hosts tags

group_vars\tag_type_iisserver.yml

Nicolas Landais

unread,
May 1, 2015, 6:07:22 PM5/1/15
to ansible...@googlegroups.com
I am curious to know what your hosts file and group_vars\tag_type_iisserver.yml look like. I am trying to add dynamic hosts to my static windows group in /etc/ansible/hosts using the following syntax
[tag_name_xzy]

[windows:children]
tag_name_xyz

as shown in the documentation and the result is : "No hosts matched" even though ec2.py does return a few hosts under the section [tag_name_xyz]. It's driving me crazy. Any help is appreciated.
Thanks

em...@nathanwebster.me

unread,
Nov 7, 2016, 2:55:10 PM11/7/16
to Ansible Project
Did you ever figure this out?  I'm currently getting "no hosts matched".  Any tips would be great! 

Bryan Banks

unread,
Feb 9, 2017, 10:59:05 AM2/9/17
to Ansible Project
To anyone who finds this and has the same problem, here's how it works:

My playbook (myplaybook.yml)

- name: Do some stuff to windows servers

  hosts: tag_OS_windows2012r2

  gather_facts: false

  connection: local

  tasks:

    - name:

      win_file:

        path: C:\foobar.txt

        state: touch


I also created a folder / file group_vars/tag_OS_windows2012r2.yml (note this file name is the same as my hosts in the playbook)


ansible_connection: winrm

ansible_ssh_port: 5986

ansible_ssh_user: Administrator

ansible_ssh_pass: mypassword123


And then call your playbook with ec2.py (and AWS profiles, if you use that)


AWS_PROFILE=main ansible-playbook -i /etc/ansible/ec2.py myplaybook.yml

Reply all
Reply to author
Forward
0 new messages