running playbook for windows plus dynamic inventory and dynamic groups_vars

Hi
I have a requirement to run playbook on hyperv compute nodes (windows) i tried the method mentioned to keep all variables .

ansible_ssh_user: Administrator
ansible_ssh_pass: password
ansible_ssh_port: 5986
ansible_connection: winrm

I use dynamic inventory to get the target hosts dynamically. Since the hosts are not static and they keep changing i cannot keep the above variables in a static file in group_vars

Question is can group_vars be passed as part of the dynamic inventory json ? Can i have a section in _meta as group_vars ? if yes what would be the structure ?

{
“_meta”: {
“hostvars”: {
“192.168.0.68”: {
“username”: “Administrator”,
“hypervisor_type”: “hyperv”,
“hypervisor_id_list”: [
“2”
],
“password”: “password”,
“port”: “5986”
}
}
},
“computenodes”: {
“hosts”: [
“192.168.0.68”
]
}
}

Hi,

you just have to add “vars” to the group name, so assuming “computenodes” is your group you would have something like:

“computenodes”: {
“hosts”: [
“192.168.0.68”
],
“vars”:{
“var1”: “Var”,
“var2”: 2
}

}

Have a look here:
https://github.com/Shaps/mongo-dynamic-inventory/blob/master/inventory.py#L55

Andrea

Thank you It works !!