Noob question - inventory and group_vars

35 views
Skip to first unread message

java_cat33

unread,
May 9, 2018, 5:07:30 AM5/9/18
to Ansible Project
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.

Edmund Cheng

unread,
May 9, 2018, 7:13:16 AM5/9/18
to Ansible Project
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/<group name>, 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.

java_cat33

unread,
May 9, 2018, 4:10:07 PM5/9/18
to Ansible Project
Thanks Edward - this sounds almost the same as doing what I performed?
Reply all
Reply to author
Forward
0 new messages