# Noob question - inventory and group\_vars

**URL:** <https://forum.ansible.com/t/noob-question-inventory-and-group-vars/27489>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [May 9, 2018, 9:07am UTC](https://forum.ansible.com/t/noob-question-inventory-and-group-vars/27489 "2018-05-09T09:07:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lee\_Drew](https://avatars.discourse-cdn.com/v4/letter/l/e0b2c6/32.png) [@Lee\_Drew](https://forum.ansible.com/u/Lee_Drew)\
**Post date:** [May 9, 2018, 9:07am UTC](https://forum.ansible.com/t/noob-question-inventory-and-group-vars/27489/1 "2018-05-09T09:07:30Z")

</div>

So far I’ve found out that if I have an inventory file (E.G inventory.yml) within a playbook folder, and a file named web.yml in group\_vars I can do a win\_ping without issues when the inventory file contains a group named [web] and a server resides within this group - cool.

I expanded the inventory.yml and added additional groups [db] and added servers to this new group.

If I run ‘ansible all -i inventory.yml -m win\_ping’ - only the server listed within the [web] group get’s a successful connection/response. The other servers listed within [db] fail with a message about failing to connect to the host via ssh.

[WARNING]: ansible\_winrm\_cert\_validation unsupported by pywinrm (is an up-to-date version of pywinrm installed?)

webserver1 | SUCCESS =\> {  
“changed”: false,  
“ping”: “pong”  
}  
db1 | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: ssh: connect to host db1 port 22: Connection timed out\r\n”,  
“unreachable”: true  
}  
db2 | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: ssh: connect to host db2 port 22: Connection timed out\r\n”,  
“unreachable”: true  
}

The web.yml file just contains connection information on how to connect to the Windows boxes (winrm etc)

I then made a copy of web.yml and named it db.yml so now I have web.yml and db.yml in the group\_vars directory and ran the same ansible command again to test the ping to all servers in the inventory file - this worked without issues across all three hosts.

I want to know if there is a smarter/easier way to do this?

What is recommended practice - single inventory file for test, single inventory file for production which you reference for your playbooks? Inventory file must contains loads of groups so I’m guessing make a bunch of copies of the files in group\_vars is not the best way to approach this…???

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Edmund\_Cheng](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Edmund\_Cheng](https://forum.ansible.com/u/Edmund_Cheng)\
**Post date:** [May 9, 2018, 11:13am UTC](https://forum.ansible.com/t/noob-question-inventory-and-group-vars/27489/2 "2018-05-09T11:13:15Z")

</div>

Hi, not sure if it will help…  
But here is what i know…

In general for group\_vars, i do the below structure

…/group\_vars/web  
…/group\_vars/db

Under those folders, you can use something like var.yml and put the variables inside.  
So when using the playbook, group names that matches the group\_vars/, the variables underneath it will get recognized.  
That is if there is some specific thing you want to differentiate, if not, you can just do  
…/group\_vars/all

And all the variables defined under it will be recognized by all servers in your inventory.

---

<div class="post-metadata">

**Author:** ![Lee\_Drew](https://avatars.discourse-cdn.com/v4/letter/l/e0b2c6/32.png) [@Lee\_Drew](https://forum.ansible.com/u/Lee_Drew)\
**Post date:** [May 9, 2018, 8:10pm UTC](https://forum.ansible.com/t/noob-question-inventory-and-group-vars/27489/3 "2018-05-09T20:10:06Z")

</div>

Thanks Edward - this sounds almost the same as doing what I performed?
