# python api on windows

**URL:** <https://forum.ansible.com/t/python-api-on-windows/21029>\
**Category:** Ansible Developer\
**Tags:** windows\
**Created:** [March 31, 2016, 5:21am UTC](https://forum.ansible.com/t/python-api-on-windows/21029 "2016-03-31T05:21:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Huan\_He](https://avatars.discourse-cdn.com/v4/letter/h/13edae/32.png) [@Huan\_He](https://forum.ansible.com/u/Huan_He)\
**Post date:** [March 31, 2016, 5:21am UTC](https://forum.ansible.com/t/python-api-on-windows/21029/1 "2016-03-31T05:21:14Z")

</div>

I am able to run the below cmd

ansible windows -m raw -u Administrator -c winrm -a “dir”

with group\_vars/windows.yml

ansible\_user: Administrator

ansible\_password: xxxxx

ansible\_port: 5986

ansible\_connection: winrm

ansible\_winrm\_server\_cert\_validation: ignore

I wonder how I can specify group\_vars/windows.yml in the api code? The code is something like this now, which works fine on Linux.

def run(self, cmd, hosts, remote\_user=‘Administrator’):

play\_source = dict(

name = ‘Ansible Win Cli PoC’,

hosts = hosts,

remote\_user = remote\_user,

gather\_facts = ‘no’,

tasks = [

dict(action=dict(module=‘raw’, args=cmd), register=‘shell\_out’),

dict(action=dict(module=‘debug’, args=dict(msg=‘{{shell\_out.stdout}}’)))

]

)

play = Play().load(play\_source, variable\_manager=self.\_variable\_manager, loader=self.\_loader)

tqm = None

try:

tqm = TaskQueueManager(

inventory=self.\_inventory,

variable\_manager=self.\_variable\_manager,

loader=self.\_loader,

options=self.\_options,

stdout\_callback=‘default’,

passwords=None

)

tqm.run(play)

finally:

if tqm is not None:

tqm.cleanup()

---

<div class="post-metadata">

**Author:** ![marc.petrivelli](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/marc.petrivelli/32/3773_2.png) [@marc.petrivelli](https://forum.ansible.com/u/marc.petrivelli)\
**Post date:** [March 31, 2016, 4:48pm UTC](https://forum.ansible.com/t/python-api-on-windows/21029/2 "2016-03-31T16:48:55Z")

</div>

If you need to explicitly include this, try using the include\_vars module. That said if you’re running against a host already in that group, all the variables in that file should already be available to you

---

<div class="post-metadata">

**Author:** ![Huan\_He](https://avatars.discourse-cdn.com/v4/letter/h/13edae/32.png) [@Huan\_He](https://forum.ansible.com/u/Huan_He)\
**Post date:** [March 31, 2016, 11:12pm UTC](https://forum.ansible.com/t/python-api-on-windows/21029/3 "2016-03-31T23:12:22Z")

</div>

Marc,  
Thanks for prompt response. How can I do it in python code?  
Thanks,  
Huan
